Isometric tilemap drawn on reverse
Posted: Sun Nov 02, 2014 6:10 pm
Hi, I've been working on a tile based game and i'm encountering weird issues related to the drawing of my tilemap.
Let me explain:
I've got a dungeontest.lua file, generated by Tiled and then reworked by another program in order to be used with love2d, which contains the raw data concerning the dungeon, something like this:
Mini-disclaimer: let's suppose all the variables you below are initialised with the correct values
Now, in the generic dungeon.lua file, which is the gamestate in which the player goes once has met a certain position I've got these functions, which help create the dungeon to be rendered
Ok, now, in this situation the dungeon is drawn, starting from (0,0) and descending, from the last cell of tileMap, that is from tileMap[12][20] (attachment 1). And that's wrong for what I want to do and I'm forced to use this piece of code in updateTilesetBatch() in order to achieve what i want (attachment 2).
I don't think it's really necessary this, but I can't really see what I am doing wrong. Can anybody help me?
Let me explain:
I've got a dungeontest.lua file, generated by Tiled and then reworked by another program in order to be used with love2d, which contains the raw data concerning the dungeon, something like this:
Mini-disclaimer: let's suppose all the variables you below are initialised with the correct values
Code: Select all
return
{
layers = {
data = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
}
}
}
Code: Select all
local function newAtlas(tileSizeX, tileSizeY, dungeon)
--this function returns a Quad table from the tileset loaded
end
local function updateTilesetBatch() --this function creates a triple dimensional matrix which will be used in dungeon.draw()
local temp = love.graphics.newQuad(0,0,0,0,0,0)
local temp_loc = {}
for i=1, #dungeon.layers do
tilesetBatch[i]={}
for x=tilesDisplayWidth, 1, -1 do
tilesetBatch[i][x] = {}
for y=tilesDisplayHeight, 1, -1 do
if tileMap[i].data[y][x]~= 0 then
tilesetBatch[i][x][y] = tileQuads[tileMap[i].data[y][x]]
else
tilesetBatch[i][x][y] = quadZero
end
end
end
end
end
local function setupTiles()
--initializes many variables and calls newAtlas(..) and updateTilesetBatch()
updateTilesetBatch()
end
function dungeon:draw() --Draws the dungeon, as simple as that, start_x and start_y are ad-hoc values needed in order for the dungeon to be drawn starting from (0,0)
cam:attach()
for i=1, #dungeon.layers do
for j = #tilesetBatch[i], 1, -1 do
for k = #tilesetBatch[i][j], 1, -1 do
if tilesetBatch[i][j][k] ~= quadZero then
love.graphics.draw(dungeon.spritesheet,tilesetBatch[i][j][k],math.floor(-zoomX*dungeon.tilewidth*0.5*(k-j))-start_x, math.floor(-zoomY*dungeon.tileheight*0.4*(j+k))-start_y,0, zoomX, zoomY)
end
end
end
end
entities:draw()
cam:detach()
ui:draw()
end
Code: Select all
for i=1, #dungeon.layers do
for x=1, math.floor(tilesDisplayWidth/2) do
temp_loc = tilesetBatch[i][x]
tilesetBatch[i][x] = tilesetBatch[i][tilesDisplayWidth-x+1]
tilesetBatch[i][tilesDisplayWidth-x+1] = temp_loc
end
for x=1, tilesDisplayWidth do
for y=1, math.floor(tilesDisplayHeight/2) do
temp = tilesetBatch[i][x][y]
tilesetBatch[i][x][y] = tilesetBatch[i][x][tilesDisplayHeight-y+1]
tilesetBatch[i][x][tilesDisplayHeight-y+1] = temp
end
end
end