modules/world: add a basic sprite system for the Actor2D
This commit is contained in:
parent
d908604dcb
commit
1a669029ea
1 changed files with 32 additions and 1 deletions
|
@ -43,6 +43,7 @@ function Actor2D:setManagers(world)
|
|||
self.world = world
|
||||
self.scene = world.scene
|
||||
self.obj = world.obj
|
||||
self.assets = self.scene.assets
|
||||
end
|
||||
|
||||
function Actor2D:setDebugColor(r,g,b)
|
||||
|
@ -69,6 +70,7 @@ function Actor2D:initPhysics(x, y, w, h, isSolid)
|
|||
self.isSolid = isSolid or false
|
||||
|
||||
self:setFilter()
|
||||
self:setSprite()
|
||||
end
|
||||
|
||||
function Actor2D:register()
|
||||
|
@ -161,6 +163,34 @@ end
|
|||
-- DRAW 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)
|
||||
end
|
||||
|
||||
function Actor2D:setSpriteScallingX(sx)
|
||||
local sx = sx or 1
|
||||
end
|
||||
|
||||
function Actor2D:setSpriteScallingY(sy)
|
||||
local sy = sy or 1
|
||||
end
|
||||
|
||||
function Actor2D:drawSprite(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||
if (self.sprite.name ~= nil) then
|
||||
local ox = oy or self.sprite.ox
|
||||
local oy = oy or 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)
|
||||
end
|
||||
end
|
||||
|
||||
function Actor2D:getCenter()
|
||||
return (self.x + (self.w / 2)), (self.y + (self.h / 2))
|
||||
end
|
||||
|
@ -170,7 +200,8 @@ function Actor2D:getViewCenter()
|
|||
end
|
||||
|
||||
function Actor2D:draw()
|
||||
-- here will be update actions
|
||||
local x, y = math.floor(self.x), math.floor(self.y)
|
||||
self:drawSprite(self.x, self.y)
|
||||
end
|
||||
|
||||
function Actor2D:drawHitbox()
|
||||
|
|
Loading…
Reference in a new issue