Wait for animation to finish?


#1

I am using the update event to send post messages to change the animation based on input.My problem is as follow:

Note: all my animation are imported inside an Atlas component

I have a Stand animation. I am basically checking in the update event, that if the velocity.x equals to zero, then use the stand animation. I have an animation attack, and whenever i trigger it using an input button, the animation finish in an instant, because the character is standing and the standing animation condition applies.

*How can i make sure that each animation is executed till it finishes?
*I am using message posting to play the animation. Can i use go.animate to animate something from an atlas. If yes, then how and would using delays in this case would be correct?
*To implement my logic for several animation overlapping, is my logic correct? i.e. update the animation in the from the update event for each frame.

I understand that my left and right animation are working fine, because they stop once i release the key, but for an attack, you only have to press the button once. I tried catching the if message_id == hash("animation_done") but this event never hits on the on_message event.


Animation - Mashing attack button (SOLVED)
#2

Animations started using the play_animation message will always play to the end unless another animation is started on the same sprite.

go.animate() is used to animate different properties such as position, rotation and so on. It can not be used to somehow play animations from an atlas.

The basic rule is that if you post a play_animation message to a sprite it will immediately replace any currently running animation on that sprite. If you want some other behaviour such as chaining one animation to the end of another animation you need to create this kind of sequencer yourself and use the animation_done message to know when an animation has finished.


#3

I have tried to intercept the animation_done message on the on_message event, but it would never hit. I am simply using the below function. Any ideas why this is happening?

function play_animation(self, anim)
  --only play animation which are not already running
  if self.anim ~= anim then
	--tell the sprite to play the animation
	msg.post("#sprite", "play_animation", {id = hash(anim)})
	--remember which animation is playing
	self.anim = anim
  end
end

#4

You will only get an animation_done message for non-looping animations. Could this be the problem? What if you add a print(message_id) at the top of the on_message() function in the same script that posted the play_animation message. Aren’t you getting any animation_done messages?


#5

Actually, that was exactly my problem and its solved now. I have one more question though. When i put a print statement in the on_input event, and press a button once, i expect the message to be printed one time, but that is not the case, as it gets printed multiple times. Why does this happen? Does this means that all the components in my project are listening to the input or is it something else?


#6

You will need to investigate the action table as well to figure out if it was a pressed, repeated or released event:

function on_input(self, action_id, action)
	if action_id == hash("myaction") then
		if action.pressed then
			print("myaction was pressed")
		elseif action.released then
			print("myaction was released")
		elseif action.repeated then
			print("myaction was repeated")
		end
	end
end

Check input settings in game.project to see how often the repeated event will be sent.