Animating Multiple Sprite2D Instances Using a Single Animation Player: Seeking Guidance

Hello Godot community,

I’m working on a ball and paddle game, akin to breakout, where I dynamically instantiate StaticBody2D brick scenes at runtime. Currently, I’m facing a challenge in synchronizing a Sprite2D scale animation across all these instantiated bricks to match the beat of music.

I have a single AnimationPlayer located at a higher level in the scene hierarchy (root) with a Sprite2D scale animation that I want each instance’s Sprite2D nodes to use. How can I achieve this synchronization?

Here’s a snippet of what I’ve tried so far:

var new_brick = brick.instantiate()
new_brick.position.x = new_brick.global_position.x + i * (brick_width + brick_gap_size)
new_brick.animation_player = brick_animation_player

var sprite_path = NodePath("Sprite2D:scale")
new_brick.animation_player.get_animation("brick_beat").track_set_path(0, sprite_path)

if new_brick.animation_player:"brick_beat")

I appreciate any guidance or suggestions on how to make all the Sprite2D nodes of these instances utilize the same AnimationPlayer for synchronized scaling.

Thank you!

If you went thus far setting up animations in code at this point it’s easier to use tweens.

If I would implement this trying to fit it into your existing system instead of redesigning everything, I would do the following:

  1. On the node that instantiates new bricks have an array/list of bricks that need to be animated.
  2. Start a new tween, animating all bricks in a for loop.
  3. Connect to the tween finished signal.
  4. When the tween is finished, start a new tween like in step 2.
  5. When you spawn new bricks, add them to the array. Don’t forget to remove bricks that are destroyed, otherwise the tween would error out.

Since the tween starts for all bricks at the same time, the animations across all bricks will be synchronized.
Additionally, you can start tweens at music beats.

1 Like

Hey @Exerion,

Awesome advice on using tweens for this issue! Your suggestion of managing an array of bricks for synchronized animations is a game-changer. Led me down a path of really cool insights. I appreciate the help!


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.