Skip to content

Hold a slice key until the slice's next key - #626

Closed
pusewicz wants to merge 1 commit into
RandyGaul:masterfrom
pusewicz:fix-sprite-slice-key-lookup
Closed

pusewicz wants to merge 1 commit into
RandyGaul:masterfrom
pusewicz:fix-sprite-slice-key-lookup

Conversation

@pusewicz

Copy link
Copy Markdown
Contributor

cf_sprite_get_slice returned the first key at or after the current frame. Aseprite holds a key until the slice's next one, and so do CF_SpriteSlice's docs and the pivot and 9-slice tables, which fill forward. So a slice keyed at frames 0 and 4 gave frame 2 the frame-4 box, and a slice keyed only at frame 0 was missing on every later frame. Sprites that key their slice on every frame, like the pivot sample, behave the same as before.

The new test embeds a 355-byte .ase (four blank frames, two tags, two slices), and it fails on the old lookup.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XG4ehbJvpCcNb3HdTURcc9

cf_sprite_get_slice returned the first key at or after the current frame,
so a slice keyed at frames 0 and 4 answered frame 2 with frame 4's box, and
a slice keyed only at frame 0 wasn't found on any later frame. Aseprite holds
a key until the next one, as CF_SpriteSlice's docs say and as the pivot and
9-slice tables already fill forward; the lookup now takes the latest key at
or before the frame.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XG4ehbJvpCcNb3HdTURcc9
Copilot AI lite review requested due to automatic review settings September 27, 2026 20:14
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The behavior change is narrowly scoped, aligns with existing CF_SpriteSlice semantics, and is covered by a focused regression test.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR fixes cf_sprite_get_slice so slice keys behave like Aseprite: a slice key is held from its keyed frame until the next key for that slice, instead of jumping ahead to the next key at/after the current frame. It also updates the public docs to match, and adds a regression test with an embedded minimal .ase to lock in the behavior.

Changes:

  • Fix slice lookup in cf_sprite_get_slice to return the latest key at or before the current (animation-offset) frame.
  • Update cf_sprite_get_slice API docs to describe the “held key” behavior and not-found semantics.
  • Add a new regression test (test_sprite_slice_keys) with embedded Aseprite data covering hold-forward and animation frame-offset behavior.
File Description
test/​test_sprite.cpp Adds a regression test validating slice key “hold until next key” behavior and frame-offset semantics.
test/​slice_keys.h Adds an embedded minimal .ase fixture used by the new slice-key test.
src/​cute_sprite.cpp Changes cf_sprite_get_slice to select the latest slice key at/before the current frame (Aseprite-like behavior).
include/​cute_sprite.h Updates the public API documentation to reflect the corrected slice lookup semantics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/slice_keys.h
Comment on lines +1 to +4
// Embedded slice_keys.ase: 4 blank 2x2 frames, tag "all" over frames 0-3 and tag
// "late" over frames 2-3. Slice "a" is keyed at frame 0 (x 0, y 0, 1x1) and at
// frame 2 (x 1, y 1, 1x1). Slice "b" is keyed only at frame 1 (x 0, y 1, 2x1).
static int slice_keys_sz = 355;
@pusewicz pusewicz closed this Sep 27, 2026
@pusewicz

Copy link
Copy Markdown
Contributor Author

PR got opened without my approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants