Skip to content

SpriteAnimation: introduce imageRange#80

Open
eulerscheZahl wants to merge 1 commit intoCodinGame:masterfrom
eulerscheZahl:animation-imageRange
Open

SpriteAnimation: introduce imageRange#80
eulerscheZahl wants to merge 1 commit intoCodinGame:masterfrom
eulerscheZahl:animation-imageRange

Conversation

@eulerscheZahl
Copy link
Copy Markdown
Contributor

@eulerscheZahl eulerscheZahl commented Apr 13, 2026

SpriteAnimation.setImages can be quite expensive, as it serializes the whole image sequence. When the animation sequences changes to something else and then changes back (because a character plays an attack animation, changes moving direction, ...), the whole sequence gets serialized again.
There is the AnimationModule as an alternative, but it's not as easy to use.

Here is an example from Code Keeper - not even quoting a full frame:
12 0 I c5o12,c5o13,c5o14,c5o15,c5o16,c5o17,c5o18,c5o19,c5o20,c5o21,c5o22,c5o23;1210 0 I c4i21,c4i22,c4i23,c4i24,c4i25,c4i26,c4i27,c4i28,c4i29,c4i30,c4i31,c4i32,c4i33,c4i34,c4i35,c4i36,c4i37,c4i38,c4i39,c4i40,c4i41;1213 0 I c4i21,c4i22,c4i23,c4i24,c4i25,c4i26,c4i27,c4i28,c4i29,c4i30,c4i31,c4i32,c4i33,c4i34,c4i35,c4i36,c4i37,c4i38,c4i39,c4i40,c4i41;

While image names don't have to be in sequence, they are in most scenarios. So it's possible to compress them by just storing the prefix, the first and last suffix.
E.g. I c5o12,c5o13,c5o14,c5o15,c5o16,c5o17,c5o18,c5o19,c5o20,c5o21,c5o22,c5o23 would become IR c5o|12|23 with this commit.

It checks, if image names are in sequence. If they are, the new imageRange property is used to serialize and deserialize. Otherwise the old images is still used as a fallback solution.
From a user perspective nothing changes, this all happens behind the scenes.

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.

1 participant