modules/world: make the actors able to clone their sprite
This commit is contained in:
parent
174b51acfa
commit
8d655f8049
1 changed files with 25 additions and 8 deletions
|
@ -225,17 +225,30 @@ function Actor2D:applyGravity(dt)
|
|||
end
|
||||
end
|
||||
|
||||
-- DRAW FUNCTIONS
|
||||
-- DRAW & SPRITES FUNCTIONS
|
||||
-- Draw the actors.
|
||||
|
||||
function Actor2D:setSprite(spritename, ox, oy)
|
||||
self.sprite = {}
|
||||
self.sprite.name = spritename or nil
|
||||
self.sprite.ox = ox or 0
|
||||
self.sprite.oy = oy or 0
|
||||
self.sprite.sx = 1
|
||||
self.sprite.sy = 1
|
||||
self.sprite.exist = (spritename ~= nil)
|
||||
self.sprite.name = spritename or nil
|
||||
self.sprite.ox = ox or 0
|
||||
self.sprite.oy = oy or 0
|
||||
self.sprite.sx = 1
|
||||
self.sprite.sy = 1
|
||||
self.sprite.exist = (spritename ~= nil)
|
||||
self.sprite.clone = nil
|
||||
end
|
||||
|
||||
function Actor2D:cloneSprite()
|
||||
if self.sprite.name ~= nil then
|
||||
self.sprite.clone = self.assets.sprites[self.sprite.name]:clone()
|
||||
end
|
||||
end
|
||||
|
||||
function Actor2D:updateSprite(dt)
|
||||
if (self.sprite.clone ~= nil) then
|
||||
self.sprite.clone:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function Actor2D:setSpriteScallingX(sx)
|
||||
|
@ -256,7 +269,11 @@ function Actor2D:drawSprite(x, y, r, sx, sy, ox, oy, kx, ky)
|
|||
local y = y + self.sprite.oy
|
||||
local sx = sx or self.sprite.sx
|
||||
local sy = sy or self.sprite.sy
|
||||
self.assets.sprites[self.sprite.name]:drawAnimation(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||
if (self.sprite.clone ~= nil) then
|
||||
self.sprite.clone:draw(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||
else
|
||||
self.assets.sprites[self.sprite.name]:drawAnimation(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue