examples/plateform: add basic sprite functions

This commit is contained in:
Kazhnuz 2019-05-01 11:17:01 +02:00
parent ce2a89b295
commit b754501102

View file

@ -3,7 +3,7 @@ local Player = Base:extend()
function Player:new(world, x, y, id) function Player:new(world, x, y, id)
Player.super.new(self, world, "player", x, y, 16, 24, true) Player.super.new(self, world, "player", x, y, 16, 24, true)
self.playerid = id self:setSprite("player", 8, 12)
end end
function Player:update(dt) function Player:update(dt)
@ -22,7 +22,17 @@ function Player:update(dt)
self.xsp = 120 self.xsp = 120
end end
self:setDirection(self.xsp)
Player.super.update(self, dt) Player.super.update(self, dt)
end end
function Player:setDirection(direction)
direction = direction or 0
if direction ~= 0 then
direction = utils.math.sign(direction)
self:setSpriteScallingX(direction)
end
end
return Player return Player