Whenever I move my character the run anim keeps playing even when I dont move, but when I do it freezes. This is my code
function init(self)
msg.post(".","acquire_input_focus")
self.runSpeed = 50
self.curAnim = "idle"
msg.post("#sprite", "play_animation", { id=hash("idle") })
self.speed = vmath.vector3()
particlefx.play("#playerparticle")
end
function update(self, dt)
local pos = go.get_position()
if self.speed.x ~= 0 then
pos = pos + self.speed * dt
go.set_position(pos)
if self.curAnim ~= "run" then
msg.post("#sprite", "play_animation", { id=hash("run") })
self.curAnim = "run"
self.curAnim = "idle"
end
elseif self.curAnim ~= "idle" then
msg.post("#sprite", "play_animation", { id=hash("idle") })
self.curAnim = "idle"
end
self.speed = vmath.vector3()
end
function on_input(self, action_id, action)
if action_id == hash("MOVE_RIGHT") then
self.speed.x = self.runSpeed
sprite.set_hflip("#sprite", false)
end
if action_id == hash("MOVE_LEFT") then
self.speed.x = self.runSpeed * -1
sprite.set_hflip("#sprite", true)
end
end