diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index a1799ee..3cf95bd 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -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