chore(baseworld): make drawing reordering part of getVisibleActors(id)

This commit is contained in:
Kazhnuz 2019-06-30 17:07:03 +02:00
parent ce48e451c1
commit a60058522b

View file

@ -144,6 +144,8 @@ end
function BaseWorld:getVisibleActors(id)
local actors = {}
if (id ~= nil) then
local camx, camy, camw, camh = self.cameras:getViewCoordinate(id)
local paddingw = camw * PADDING_VALUE
local paddingh = camh * PADDING_VALUE
@ -152,7 +154,20 @@ function BaseWorld:getVisibleActors(id)
local w = camw + paddingw * 2
local h = camh + paddingh * 2
return self:getActorsInRect(x, y, w, h)
actors = self:getActorsInRect(x, y, w, h)
else
actors = self:getActors()
end
table.sort(actors, function(a,b)
if (a.depth == b.depth) then
return a.creationID < b.creationID
else
return a.depth > b.depth
end
end)
return actors
end
-- BODIES MANAGEMENT FUNCTIONS
@ -426,20 +441,7 @@ function BaseWorld:draw(dt)
end
function BaseWorld:drawActors(id)
local actors
if (id == nil) then
actors = self:getActors()
else
actors = self:getVisibleActors(id)
end
table.sort(actors, function(a,b)
if (a.depth == b.depth) then
return a.creationID < b.creationID
else
return a.depth > b.depth
end
end)
local actors = self:getVisibleActors(id)
for i,v in ipairs(actors) do
v:draw()