Create a tile grid without images?

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
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Create a tile grid without images?

Post by Ryne »

Hi, again..

Right now I'm using this to create the set amount of tiles used for my game. I'm not sure if it's actually a bad thing or not - but incase - is there away to eliminate images entirely? I really just need a grid of numbers.

Code: Select all

	tile = {} -- tiles
	for i = 0, 32 do
		tile[i] = love.graphics.newImage("res/tile0.png")
	end	

	mapvars = {} -- map variables
				
	mapvars.w = #map[1]
	mapvars.h = #map
	mapvars.x = 0
	mapvars.y = 0
	mapvars.buff = 2
	mapvars.dispw = 16
	mapvars.disph = 16
	
	tilevars = {} -- tilevars
		
	tilevars.w = 8
	tilevars.h = 8
As you can see, I have 33 tiles all using the same image, but these only serve as markers since I don't actually use any of them.

Code: Select all

function drawWorld()

	firsttilex = math.floor(mapvars.x / tilevars.w)
	firsttiley = math.floor(mapvars.y / tilevars.h)
	
	for y = 1, (mapvars.disph + mapvars.buff) do
		for x = 1, (mapvars.dispw + mapvars.buff) do
		
			if y + firsttiley >= 1 and y + firsttiley <= mapvars.h
				and x + firsttilex >= 1 and x + firsttilex <= mapvars.w
			then
			
                love.graphics.draw(
                    tile[map[y + firsttiley][x+firsttilex]], 
                    (x*tilevars.w) - tilevars.w, 
                    (y*tilevars.h) - tilevars.h)
            end
		end
	end

end
then my trees and objects are drawn using:

Code: Select all

function drawTrees()

	for i = 1, #map do
		for l = 1, #map do
			if map[i][l] ~= 0 then
			love.graphics.drawq(images.tileset, quads[map[i][l]], mapToWorld(l-1, i-2))
			end
		end
	end

end
any ideas?
@rynesaur
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Create a tile grid without images?

Post by Ellohir »

I don't know if this is what you want but there we go. This should print a number grid on your map, aligned to the beginning of each tile, showing a "(x,y)" text. Or a "(y,x)", not sure of that part xD

Code: Select all

function drawNumberTiles()
   for i = 1, #map do
      for l = 1, #map do
         love.graphics.print("("..l..","..i..")", mapToWorld(l-1,i-2))
      end
   end
end
You should be able to substitute "drawWorld" for "drawNumberTiles" on the love.draw, give it a try and tell us if it worked ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 214 guests