From f71c3b3548260a0d56bde5299557debe59701c2a Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 May 2019 15:23:04 +0200 Subject: [PATCH] example/plateform: animate the player --- examples/gameplay/plateform/actors/player.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/gameplay/plateform/actors/player.lua b/examples/gameplay/plateform/actors/player.lua index 8c32364..f96059c 100644 --- a/examples/gameplay/plateform/actors/player.lua +++ b/examples/gameplay/plateform/actors/player.lua @@ -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)