isometric displays

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
greentiger
Prole
Posts: 16
Joined: Tue Mar 11, 2014 6:48 pm
Location: united states

isometric displays

Post by greentiger »

hello all,

i have a problem with figuring out how to do several things with a 2-dimensional array for isometric display. right now i'm trying to figure out how to expand the 2-dimensional tutorial to add height. i was thinking of having the 2d system hold a string that determines the tile type and its height.

for example:
grid[2][4] = "2,1"
grid[6][5] = "2,2"

with the first number being the terrain type/tile and the second value being its height.

i'm using the draw routine as below:

Code: Select all

function gridDraw()
	for x = 1,gridSizex do
		for y = 1,gridSizey do
			local tempx = grid_x + ((y-x) * (blockWidth / 2))
			local tempy = grid_y + ((x+y) * (blockFace)) - (blockFace * (gridSizey / 2))
				if grid[x][y] == 1 then
					love.graphics.draw(tilesetImage, grass, tempx, tempy)
				elseif grid[x][y] == 2 then
					love.graphics.draw(tilesetImage, dirt, tempx, tempy)
				end
		end
	end
end

my question is as follows:

is there a better way to store the map data; and how do i change the function to draw height?

thanks!

EDIT:
i think what i'd like to do is that grid[x][y] value will store a string = "2,1" with the top tile determining properties of tiles beneath. like if it's topped by a grass tile all underneath tiles will automatically be dirt and if a stone tile all subsequent tiles will also be stone.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: isometric displays

Post by micha »

If you want to store numbers, I highly suggest using number variables for that, not strings. To store two pieces of information in each cell, there are two possible ways to implement this (which are better than storing a string "2,1"):
  • Make two tables. One for the type and one for the height:

    Code: Select all

    tile[x][y] = 2
    height[x][y] = 1
    -- instead of grid[x][y] = "2,1"
  • or store a table in each cell:

    Code: Select all

    grid[x][y].tile = 2
    grid[x][y].height = 1
In both cases it is much easier to extract the information, than from the string solution.

For the other question, how to draw isometric tiles with height. Simply add the height to the y-coordinate:

Code: Select all

local tempx = grid_x + ((y-x) * (blockWidth / 2))
local tempy = grid_y + ((x+y) * (blockFace)) - (blockFace * (gridSizey / 2)) - z * blockHeight
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 7 guests