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,7 +225,7 @@ function Actor2D:applyGravity(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW & SPRITES FUNCTIONS
|
||||||
-- Draw the actors.
|
-- Draw the actors.
|
||||||
|
|
||||||
function Actor2D:setSprite(spritename, ox, oy)
|
function Actor2D:setSprite(spritename, ox, oy)
|
||||||
|
@ -236,6 +236,19 @@ function Actor2D:setSprite(spritename, ox, oy)
|
||||||
self.sprite.sx = 1
|
self.sprite.sx = 1
|
||||||
self.sprite.sy = 1
|
self.sprite.sy = 1
|
||||||
self.sprite.exist = (spritename ~= nil)
|
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
|
end
|
||||||
|
|
||||||
function Actor2D:setSpriteScallingX(sx)
|
function Actor2D:setSpriteScallingX(sx)
|
||||||
|
@ -256,8 +269,12 @@ function Actor2D:drawSprite(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
local y = y + self.sprite.oy
|
local y = y + self.sprite.oy
|
||||||
local sx = sx or self.sprite.sx
|
local sx = sx or self.sprite.sx
|
||||||
local sy = sy or self.sprite.sy
|
local sy = sy or self.sprite.sy
|
||||||
|
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)
|
self.assets.sprites[self.sprite.name]:drawAnimation(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:getCenter()
|
function Actor2D:getCenter()
|
||||||
|
|
Loading…
Reference in a new issue