Animation not playing while character moving

Hello there.
My character will only play animation after my character stop moving.

Here the sample of code:

elseif action_id == hash(“right”) then
self.input.x = 1
msg.post("#sprite", “play_animation”, {id = hash(“right”)})
end

Could it be that you’re playing the animation every frame, thus restarting it?

What if you check for the action.pressedtoo?

elseif action.pressed and action_id == hash(“right”) then
    self.input.x = 1
    msg.post("#sprite", “play_animation”, {id = hash(“right”)})
end
2 Likes

thanks for the reply. After tried it, my character only move a little. So i need to press right continuously to move to the right.

Btw, I tried new if statement. If the speed ==250, play_animation. The problem still there. The animation will only be played after the character stop moving.

I think it continuously restart the animation when i pressed the button, just like u said.

2 Likes

Fix it!
I need to separate it.

elseif action_id == hash("right") then
	self.input.x = 1
	if action.pressed then
		msg.post("#sprite", "play_animation", {id = hash("right")})
	end
end
2 Likes

Good to hear that you solved it! I have any example showing how to deal with animation and key states here: https://github.com/britzl/publicexamples/tree/master/examples/play_animation

1 Like