Animations from images of different sizes

Here’s a simple animation to illustrate what I mean:

bad

The character jumps around as the figure is off-centre in the second sprite. What I do to solve this is that I pad the sprites with empty space, which works well enough:

good

It feels wasteful, though. Fixing the issue programmatically sounds like a nightmare too. It seems like I’m missing some easier way to deal with this. Or maybe it’s the editor that’s missing it…

1 Like

I think there are some atlas packers that solve this by automatically cropping them and storing the center offset in the atlas data for every single image. Obviously Defold’s packer isn’t that fancy. Maybe when they add polygon trimming to atlases we will get this.

I can’t think of any way to do it that wouldn’t be very tedious. Though “tedious” depends on how many frames of animation you have. If you only have a few dozen one-frame “animations” like your example then it wouldn’t be hard to make a lua module mapping animation IDs to a center-offset, and add an extra game object to offset the sprite whenever you change animations.

One solution could be to break your sprite into multiple pieces. In your example case, if you made the weapon a separate sprite, then your character body could be cropped a lot closer, and overall you would probably save some space.

But is this really necessary? With low-res pixel art like this, will you end up wasting more than…a megabyte? It depends on the number of animations and your target size.

2 Likes

I used the tiny sprite as an example, but right now I’m working with 350 x 350 pixel sprites including the padding, while some of the smaller frames would fit into 80 x 120 image. The waste is still probably negligible in the long run and I’m not too worried because of size or performance, but I’d rather not fall into a bad habit if there’s a better way.

Edit: I cropped the extra space in one of the images and the new size is less than half of the padded version… but then again we’re talking 11 vs 25 kb, while there’s nearly 50 MB worth of music already. Besides, I don’t expect the game to be really played anywhere outside of my workplace. As long as it’s playable on three specific PCs, I’m good.

4 Likes

With Interrogation we had to trim the individual sprites, then wrote a Python script that would convert atlas animations into a format playable manually by a Lua script. It’s obviously a stop-gap solution until Defold implements better packing when sprite trim modes are enabled, but it worked for us at the time.

3 Likes

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)