Bop in a sprite

Godot Version

4.7.2

Question

I’m trying to make a sprite bop to a beat with scaling down, then back up. How can I do that with just code and not AnimationPlayer?

Tweens.

var tween = get_tree().create_tween()
tween.tween_property($Sprite, "modulate", Color.RED, 1.0)
tween.tween_property($Sprite, "scale", Vector2(), 1.0)
tween.tween_callback($Sprite.queue_free)

This sequence will make the $Sprite node turn red, then shrink, before finally calling Node.queue_free() to free the sprite. Tweeners are executed one after another by default. This behavior can be changed using parallel() and set_parallel().

Check the bpm-sync demo here:

To get a sense of how to sync the visuals with the audio.

I’d avoid using tweens as it’s not possible to manually control how they update. I’d use an AnimationPlayer with AnimationMixer.callback_mode_process set to Manual and manually advancing the animation with AnimationMixer.advance()