hello i am trying to play the idle animation when the player stop moving how, please this is the code:
local function play_animation(self, animation)
if self.current_animation ~= animation then
self.current_animation = animation
sprite.play_flipbook("#sprite", animation)
end
end
function init(self)
msg.post(".", "acquire_input_focus")
msg.post("camera", "follow")
self.follow = true
self.current_animation = nil
end
function on_input(self, action_id, action)
local pos = go.get_position()
local speed = 1
if action_id == hash("up") then
pos.y = pos.y + speed
msg.post("camera", "follow")
play_animation(self, hash("down"))
elseif action_id == hash("down") then
pos.y = pos.y - speed
msg.post("camera", "follow")
play_animation(self, hash("down"))
elseif action_id == hash("left") then
pos.x = pos.x - speed
msg.post("camera", "follow")
play_animation(self, hash("down"))
elseif action_id == hash("right") then
pos.x = pos.x + speed
msg.post("camera", "follow")
play_animation(self, hash("down"))
end
go.set_position(pos)
end