modules/world: make the actors able to clone their sprite

This commit is contained in:
Kazhnuz 2019-05-05 13:17:43 +02:00
parent 174b51acfa
commit 8d655f8049

View file

@ -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