improvement: rework layer drawing code
This commit is contained in:
parent
9d589dba8f
commit
a5f362ceaa
3 changed files with 60 additions and 14 deletions
|
@ -398,12 +398,15 @@ function BaseWorld:draw(dt)
|
||||||
local camNumber = self.cameras:getViewNumber()
|
local camNumber = self.cameras:getViewNumber()
|
||||||
|
|
||||||
if (camNumber == 0) then
|
if (camNumber == 0) then
|
||||||
self:drawMap()
|
self:drawLowerLayers()
|
||||||
self:drawActors()
|
self:drawActors()
|
||||||
|
self:drawUpperLayers()
|
||||||
else
|
else
|
||||||
for i=1, camNumber do
|
for i=1, camNumber do
|
||||||
self.cameras:attachView(i)
|
self.cameras:attachView(i)
|
||||||
self:drawMap(i)
|
self:drawLowerLayers(i)
|
||||||
|
self:drawActors(i)
|
||||||
|
self:drawUpperLayers(i)
|
||||||
self.cameras:detachView(i)
|
self.cameras:detachView(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -417,6 +420,18 @@ function BaseWorld:drawActors(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BaseWorld:drawUpperLayers()
|
||||||
|
if (self.map ~= nil) then
|
||||||
|
self.map:drawUpperLayers()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseWorld:drawLowerLayers()
|
||||||
|
if (self.map ~= nil) then
|
||||||
|
self.map:drawLowerLayers()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function BaseWorld:drawMap(id)
|
function BaseWorld:drawMap(id)
|
||||||
if (self.map ~= nil) then
|
if (self.map ~= nil) then
|
||||||
self.map:draw()
|
self.map:draw()
|
||||||
|
|
|
@ -85,6 +85,10 @@ function ParentMap:getDimensions()
|
||||||
return core.screen:getDimensions()
|
return core.screen:getDimensions()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ParentMap:drawLowerLayers()
|
||||||
|
self:draw()
|
||||||
|
end
|
||||||
|
|
||||||
function ParentMap:getBox()
|
function ParentMap:getBox()
|
||||||
local x1, y1, x2, y2 = self:getPadding()
|
local x1, y1, x2, y2 = self:getPadding()
|
||||||
local w, h = self:getDimensions()
|
local w, h = self:getDimensions()
|
||||||
|
|
|
@ -10,6 +10,26 @@ function StiMap:new(world, mapfile)
|
||||||
StiMap.super.new(self, world)
|
StiMap.super.new(self, world)
|
||||||
self:setBackgroundColorFromTable(self.sti.backgroundcolor)
|
self:setBackgroundColorFromTable(self.sti.backgroundcolor)
|
||||||
self.mapname = self:getMapName(mapfile)
|
self.mapname = self:getMapName(mapfile)
|
||||||
|
|
||||||
|
self.objectlayer = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function StiMap:loadObjects()
|
||||||
|
self:loadCollisions()
|
||||||
|
self:loadPlayers()
|
||||||
|
self:loadActors()
|
||||||
|
self.objectlayer = self:getObjectLayer()
|
||||||
|
end
|
||||||
|
|
||||||
|
function StiMap:getObjectLayer()
|
||||||
|
local objectlayer = 0
|
||||||
|
for i, layer in ipairs(self.sti.layers) do
|
||||||
|
if (layer.name == "objects") then
|
||||||
|
objectlayer = i
|
||||||
|
end
|
||||||
|
self.nbrLayer = i
|
||||||
|
end
|
||||||
|
return objectlayer
|
||||||
end
|
end
|
||||||
|
|
||||||
function StiMap:getMapName(mapfile)
|
function StiMap:getMapName(mapfile)
|
||||||
|
@ -224,21 +244,28 @@ end
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
-- Draw the map
|
-- Draw the map
|
||||||
|
|
||||||
function StiMap:draw(i)
|
function StiMap:drawUpperLayers()
|
||||||
local haveDrawnObjects = false
|
if (self.objectlayer > 0) then
|
||||||
for _, layer in ipairs(self.sti.layers) do
|
for i = self.objectlayer, self.nbrLayer, 1 do
|
||||||
|
self:drawLayer(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function StiMap:drawLowerLayers()
|
||||||
|
for i = 1, self.objectlayer, 1 do
|
||||||
|
self:drawLayer(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function StiMap:drawLayer(id)
|
||||||
|
local layer = self.sti.layers[id]
|
||||||
|
if (layer ~= nil) then
|
||||||
if layer.visible and layer.opacity > 0 and (layer.type == "tilelayer") then
|
if layer.visible and layer.opacity > 0 and (layer.type == "tilelayer") then
|
||||||
|
print("upper " .. id)
|
||||||
self.sti:drawLayer(layer)
|
self.sti:drawLayer(layer)
|
||||||
else
|
|
||||||
if (layer.name == "objects") then
|
|
||||||
haveDrawnObjects = true
|
|
||||||
self.world:drawActors(i)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (not haveDrawnObjects) then
|
|
||||||
self.world:drawActors(i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return StiMap
|
return StiMap
|
||||||
|
|
Loading…
Reference in a new issue