example/plateform: animate the player

This commit is contained in:
Kazhnuz 2019-05-05 15:23:04 +02:00
parent 53df3c125c
commit f71c3b3548

View file

@ -27,6 +27,20 @@ function Player:update(dt)
self:setDirection(self.xsp)
Player.super.update(self, dt)
self:setAnimation()
end
function Player:setAnimation()
self:setCustomSpeed(math.abs(self.xsp) / 12)
if (self.onGround) then
if math.abs(self.xsp) > 0 then
self:changeAnimation("walk", false)
else
self:changeAnimation("idle", true)
end
else
self:changeAnimation("jump", true)
end
end
function Player:setDirection(direction)