Not play animation while another animation is playing (SOLVED)

#1

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.

0 Likes

#2

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

0 Likes

#3

you need some if statements and some self.properties.

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

1 Like

#4
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.

0 Likes

#5
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

#6

Thank you for your help!

0 Likes

#7

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

1 Like