Isometric tilemap drawn on reverse

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
fedexist
Prole
Posts: 6
Joined: Mon Jul 28, 2014 7:23 pm

Isometric tilemap drawn on reverse

Post by fedexist »

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

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}
      }
}
}
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

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

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).

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
I don't think it's really necessary this, but I can't really see what I am doing wrong. Can anybody help me?
Attachments
the way i'd like
the way i'd like
attached2.png (50.25 KiB) Viewed 3015 times
the way i don't want
the way i don't want
attached1.png (55.48 KiB) Viewed 3015 times
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: Isometric tilemap drawn on reverse

Post by artofwork »

upload a love file and we can help you :)
lachlaan
Prole
Posts: 30
Joined: Sun Jun 30, 2013 7:23 pm

Re: Isometric tilemap drawn on reverse

Post by lachlaan »

"tilesetBatch[x][y] = tileQuads[tileMap.data[y][x]]"

You're assigning the values flipped is my best guess. assigning the y , x coords to x, y coords. That way tile 1x20 will be assigned to tile 20x1 of a matrix.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 30 guests