Page 1 of 1

Tile map drawing (Drawable expected, got nil)

Posted: Wed Apr 04, 2018 7:18 pm
by AlexCalv
This is map drawing code

Code: Select all

function draw_map()
	for y = 1, map_display_h do
		for x = 1, map_display_w do
			love.graphics.draw(tile[map[y+map_y][x+map_x]],0,0)
			--love.graphics.draw(tile[map[2][2]],0,0)
			--love.graphics.draw(tile[level[y][x]], x*50, y*50)
			--love.graphics.draw(tiles, x*50, y*50)
			--love.graphics.draw(tile[map[y+map_y][x+map_x]],(x*tile_w)+map_offset_x,(y*tile_h)+map_offset_y)
		end
	end
end
and there is the other tile related stuff inside love.load()

Code: Select all

	tile = {}
	for i = 0, 2 do
		tile[i] = love.graphics.newImage("tile" ..i.. ".png")
	end

	map_display_w = 25
	map_display_h = 9
	map_x = 0
	map_y = 0

	map={"0000000000000000000000000",
		 "0111111111111111111111110",
		 "0111111111111111111111110",
		 "0111111111111111111111110",
		 "0111111111111111111111110",
		 "0111111111111111111111110",
		 "0111111111211111211111110",
		 "0111211111111111211112110",
		 "0000000000000000000000000",
		}
I'm just sitting here very confused because I've followed the tutorial on the wiki almost to a tee and it simply won't draw the map.

Re: Tile map drawing (Drawable expected, got nil)

Posted: Thu Apr 05, 2018 2:04 am
by zorg
It may be an issue with lua not allowing you to index strings like tables? Your first code block treats map as a 2 dimensional table, but the second one has it be a 1D one with strings in it. You can't index strings with [].

Re: Tile map drawing (Drawable expected, got nil)

Posted: Thu Apr 05, 2018 2:31 am
by AlexCalv
zorg wrote: Thu Apr 05, 2018 2:04 am It may be an issue with lua not allowing you to index strings like tables? Your first code block treats map as a 2 dimensional table, but the second one has it be a 1D one with strings in it. You can't index strings with [].
Yeah I ended up taking a nap and fixed it when I woke up. The map needed to be setup like so

Code: Select all

map={
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
	{0,0,0,0,0,1,0,1,0,1,0,2,0,0,2,0,1,0},
}
Just an oversight on my part really, now I just need to figure out why my tiles are being loaded diagonally instead of in a square grid.

Re: Tile map drawing (Drawable expected, got nil)

Posted: Thu Apr 05, 2018 11:20 pm
by pgimeno
AlexCalv wrote: Thu Apr 05, 2018 2:31 am Just an oversight on my part really, now I just need to figure out why my tiles are being loaded diagonally instead of in a square grid.
Are you using quads? That sounds like passing a wrong horizontal size while creating the quad (the image size parameter, not the quad size parameter).