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
1 changed files with 24 additions and 22 deletions

View File

@ -144,15 +144,30 @@ end
function BaseWorld:getVisibleActors(id) function BaseWorld:getVisibleActors(id)
local camx, camy, camw, camh = self.cameras:getViewCoordinate(id) local actors = {}
local paddingw = camw * PADDING_VALUE if (id ~= nil) then
local paddingh = camh * PADDING_VALUE local camx, camy, camw, camh = self.cameras:getViewCoordinate(id)
local x = camx - paddingw local paddingw = camw * PADDING_VALUE
local y = camy - paddingh local paddingh = camh * PADDING_VALUE
local w = camw + paddingw * 2 local x = camx - paddingw
local h = camh + paddingh * 2 local y = camy - paddingh
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 end
-- BODIES MANAGEMENT FUNCTIONS -- BODIES MANAGEMENT FUNCTIONS
@ -426,20 +441,7 @@ function BaseWorld:draw(dt)
end end
function BaseWorld:drawActors(id) function BaseWorld:drawActors(id)
local actors local actors = self:getVisibleActors(id)
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)
for i,v in ipairs(actors) do for i,v in ipairs(actors) do
v:draw() v:draw()