Godot Version
v4.3.stable.official [77dcf97d8]
Question
I’m new to Godot and working on a snake clone. I decided to animate the snake by having each “cell” of the snake body play a short animation. I’m running into an issue where I’m unable to get the animations to synchronize perfectly at higher framerates, which is causing the game to appear jittery.
In my project I have a “player” scene which is composed on multiple “player_part” scenes. Without going into too much detail on movement, the player scene takes the player_part scene as a PackedScene, instantiates new player_parts at the front of the snake and destroys the old ones at the back. The player_part scenes have a root Area2D node and an AnimatedSprite2D child. The AnimatedSprite2D has 8 animation frames with looping turned off.
The player scene creates multiple instances of the player_part scene and stores them in a list. The player scene also creates a special “timer_part” instance of the player_part scene which is intended to synchronize the animations of the other player_part scenes. The animation_finished() signal of this timer_part is connected to a function in the player_part script which emits a signal connected to a function in the player script called cycle().
The cycle() function iterates over the player_part list and for each player_part sets the sprite frame and progress to 0 and calls play() on the sprite. The cycle function also sets the sprite frame and progress to 0 and calls play() on the timer_part.
The player_part scenes will play their animations in sync when the animations are played slowly (e.g. 8 fps), however when I speed up the animations (e.g. 32 fps) they become out of sync, giving the overall animation of the game a lurching appearance. This happens when I increase the speed by setting the frame rate of the SpriteFrames or by increasing the speed scale of the AnimatedSprite2D. The desynchronization is inconsistent, and doesn’t happen for every player_part or on every cycle.
What might be causing the animations to be out of sync and how can I change my project to ensure that they stay in sync? Is there a more conventional way of doing this?