Swapping textures between animations in AnimationPlayer shows frame 0 for a split second before playing the animation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By elboman

Hey everyone,

I’m trying to do pixel art 2d animations in Godot with the AnimationPlayer as suggested by many. I have multiple sprite sheet for the different states of the character (idle, walking, running, attacking) and I’d like to handle everything in a single AnimationPlayer node.

To do this, in each animation, I keyframe texture, vframe and hframe so that each animation can have its own texture.

It seems to work great, except for 1 (big) problem: whenever I’m switching animation (via code or in the animation editor) between two anims that use different textures, on change, for a split second, the new texture get set with a frame of 0 (which isn’t part of the animation itself).

So each time I switch, I always see the frame 0 for a split second and then the animation plays correctly, which makes it unusable this way.

I cannot find any info about using multiple sprite sheets in a single AnimationPlayer other than this way.

The only real solution I see is to merge everything into a single texture and simply don’t change that on animation but that kinda defeats the purpose of having anything keyframeable.

Any suggestion?

example of the problem with a spritesheet taken online: goes to frame 0 for a split second (also visible in game) - Album on Imgur

You probably already know about this as an alternative, but it’s possible to use an AnimatedSprite instead of a Sprite/AnimationPlayer combo if splitting the spritesheet into individual frames is possible for you. If you have access to a pixel art oriented image editor like aseprite it’s pretty straightforward iirc.

markopolo | 2018-04-09 15:36

Thanks for the info. Yeah I was aware of the possibility of using AnimatedSprite in place of the AnimationPlayer, but kinda defeats the purpose of the tool, as I do like the cool things AnimationPlayer provides (like calling functions during animations, swapping textures, etc).

I’m not sure if it’s only me experiencing this issue of if anybody else does. At least we would be able to figure out if I’m doing something wrong or if it’s some kind of bug in Godot.

Also, I’m not sure that under the hood using the AnimatedSprite is as efficient as the AnimationPlayer in terms of batching the changes and minimising texture swaps on the GPU (nor I am an expert on this, so I may be totally wrong).

elboman | 2018-04-25 13:12