Not play animation while another animation is playing (SOLVED)

How can you stop your game object from playing an animation while another animation is already going on.
My game object attacks when I click my mouse. I want to make my game object to not play the attack animation if attack animation is already going on.

can you show your script?
because i did not realise your question.

you need some if statements and some self.properties.

show us your script and I’ll show you what i mean

1 Like
if action_id == hash("touch") and action.pressed then 
		msg.post("#sprite", "enable")
		sprite.play_flipbook("#sprite", "attack", anim_done)
end

With this code, when i click, the animation restarts every time. I want to make sure that animation doesn’t start again until it is over.

if action_id == hash("touch") and action.pressed then 
	msg.post("#sprite", "enable")
	if self.attacking == nil then
		sprite.play_flipbook("#sprite", "attack", anim_done)
		self.attacking = true
	end
end

Now, you have a property, called self.attacking, which turns to true when the attack begins.

You also can’t start attacking unless self.attacking equals nil.

The last part is putting

self.attacking = nil

in your function called anim_done. That means self.attacking is reset to nil once the attack is done, and can be called again

2 Likes

Thank you for your help!

And here’s another example showing this: https://github.com/britzl/publicexamples/tree/master/examples/play_animation

1 Like