feat: implement fake y-sorting for tiles
This commit is contained in:
parent
70029ba7bd
commit
9c4efa3512
2 changed files with 39 additions and 0 deletions
|
@ -138,6 +138,23 @@ function StiWrapper:getTileTypeAtPoint(x, y)
|
|||
return self:getTileTypeAtCoord(xx, yy)
|
||||
end
|
||||
|
||||
function StiWrapper:haveUpperLayerAtCoord(x, y)
|
||||
local xx, yy = self:convertPixelToTile(x, y)
|
||||
local haveLayer = false
|
||||
if (self.objectlayer > 0) then
|
||||
for i = self.objectlayer, self.nbrLayer, 1 do
|
||||
local layer = self.sti.layers[i]
|
||||
if layer.visible and layer.opacity > 0 and (layer.type == "tilelayer") then
|
||||
local _, tileid = self:getTileId(layer.name, xx, yy)
|
||||
if (tileid > 0) then
|
||||
haveLayer = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return haveLayer
|
||||
end
|
||||
|
||||
function StiWrapper:getTileTypeAtCoord(x, y)
|
||||
local canSearch = true
|
||||
local currentType = nil
|
||||
|
|
|
@ -128,6 +128,27 @@ end
|
|||
|
||||
|
||||
function TiledMultiMap:drawUpperLayers()
|
||||
local player = self.world.players[1].actor
|
||||
local pos1AUpperLayer = self:haveUpperLayerAtCoord(player.x, player.y + 8)
|
||||
local pos2AUpperLayer = self:haveUpperLayerAtCoord(player.x + 16, player.y + 8)
|
||||
|
||||
local y = math.floor((player.y)/16)*16
|
||||
if (pos1AUpperLayer or pos2AUpperLayer) then
|
||||
y = math.floor((player.y - player.z)/16)*16
|
||||
end
|
||||
local camx, camy = self.world.cameras:getViewCoordinate(1)
|
||||
local viewy = math.floor(y - camy - 16)
|
||||
love.graphics.setScissor(0, viewy, 424, 240)
|
||||
self:drawUpperWrappers()
|
||||
love.graphics.setScissor()
|
||||
end
|
||||
|
||||
function TiledMultiMap:haveUpperLayerAtCoord(x, y)
|
||||
local wrapper = self:getMapAtPoint(x, y)
|
||||
return wrapper:haveUpperLayerAtCoord(x, y)
|
||||
end
|
||||
|
||||
function TiledMultiMap:drawUpperWrappers()
|
||||
local x, y, w, h = self.world.cameras:getViewCoordinate(1)
|
||||
local listWrapper = self:getMapsInRect(x, y, w, h)
|
||||
for i, wrapper in ipairs(listWrapper) do
|
||||
|
@ -141,6 +162,7 @@ function TiledMultiMap:drawLowerLayers()
|
|||
for i, wrapper in ipairs(listWrapper) do
|
||||
wrapper:drawLowerLayers()
|
||||
end
|
||||
self:drawUpperWrappers()
|
||||
end
|
||||
|
||||
return TiledMultiMap
|
||||
|
|
Loading…
Reference in a new issue