Page 1 of 1

Isometric

Posted: Sun Jan 22, 2012 8:51 pm
by legendman3
I tried using the code from this part of the wiki:
https://love2d.org/wiki/Tutorial:Isometric_Graphics

When i enter it into the lua file i get this:

Code: Select all

function love.load()
	block_width = grass:getWidth()
	block_height = grass:getHeight()
	block_depth = block_height / 2
	
	grid_size = 20
	grid = {}
	for x = 1,grid_size do
		grid[x] = {}
		for y = 1,grid_size do
			grid[x][y] = 1
		end
	end
	
	grid[2][4] = 2
	grid[6][5] = 2
	
	for x = 1,grid_size do
		for y = 1,grid_size do
			if grid[x][y] == 1 then
				love.graphics.draw(grass,
					grid_x + ((y-x) * (block_width / 2)),
					grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2)))
			else -- grid[x][y] == 2
				love.graphics.draw(dirt,
					grid_x + ((y-x) * (block_width / 2)),
					grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2)))
			end
		end
	end
end
Then i get a error about grass or something:
VvdGK.png
VvdGK.png (6.69 KiB) Viewed 228 times
So what code am i missing?

Re: Isometric

Posted: Sun Jan 22, 2012 9:20 pm
by tentus
You need to make an image called grass. It needs to be before line 2, "block_width = grass:getWidth()".

Code: Select all

grass = love.graphics.newImage("filename.png")

Re: Isometric

Posted: Sun Jan 22, 2012 9:34 pm
by legendman3
Hooray i got all the code worked out!
EzAQK.png
EzAQK.png (13.52 KiB) Viewed 227 times