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,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,9 +269,13 @@ 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()
return (self.x + (self.w / 2)), (self.y + (self.h / 2)) return (self.x + (self.w / 2)), (self.y + (self.h / 2))