Ask your question here! Try to give as many details as possible
Hi everyone,
i am making a 2d platformer; while playing an animation (“attack”) it run another animation (“idle”) without fully run the previous animation…Mmmm, i thougth a way so solve this probblem is defining come flag variable to indicate wn animation is already running…what do you think about ?
ok, considering I defined this to play the several animations:
var animation_player: AnimationPlayer
Could I check if no one animation is being played??
Yes, as @paintsimmon mentioned you can use is_playing:
if not animation_player.is_playing():
# do-stuff
Or you use current_animation to get the currently playing animation (it’s "" when none is playing). Or you connect/await the animation_finished signal as @TokyoFunkScene suggested and start the next animation when the previous is finished.
Or you use queue to queue the next animation.
do not use an AnimationPlayer on its own unless it’s for something very simple, and in that case an AnimatedSprite would be better.
explosions, single looped animations = AnimatedSprite
characters, enemies, a chest, a door = AnimationPlayer with AnimationTree
Your other question was about setting up collisions? and I told you to use a state machine?
well with an AnimationTree you could define in what order you want the animations to run, or if an animation must not transition at all, like a death animation.
idle -> hurt -> death
idle -> electricity -> death
you can also make them go back when a condition is met, like with walking:
idle -> walk
walk -> idle
an AnimationTree will also ensure that an animation finishes playing before going into the next one, and you can set it to smoothly transition, blending frames from one with the next.