Level Generation

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
kylewatson98
Prole
Posts: 13
Joined: Thu Feb 28, 2013 9:02 pm

Level Generation

Post by kylewatson98 »

Hey, I have developed a game and now I am wanting to use sprites to replace the LÖVE geometry with sprites. So I have started dabbling and messing with Sprite batches and quads (I have never used these before) and I have tried to make a simple level generator:

Code: Select all

function love.load()
	level = {}
	for i=1, 25 do
		table.insert(level, {})
		for i2 = 1, 33 do
			table.insert(level[i], math.random(1, 5))
		end
	end
	love.graphics.setDefaultImageFilter("nearest", "nearest")
	tileset = love.graphics.newImage("tileset.png")
	tickbox_q = love.graphics.newQuad(0, 24, 24, 24, 384, 202)
	r_star_q = love.graphics.newQuad(24, 0, 24, 24, 384, 202)
	g_star_q = love.graphics.newQuad(72, 0, 24, 24, 384, 202)
	explos_q = love.graphics.newQuad(96, 24, 24, 24, 384, 202)
	invdot_q = love.graphics.newQuad(48, 48, 24, 24, 384, 202)
	spriteBatch = love.graphics.newSpriteBatch(tileset, 25)
	for i = 1, #level do
		for i2 = 1, #level[i] do
			if level[i][i2] == 1 then
				spriteBatch:addq(tickbox_q, (i - 1)*24, (i2 - 1)*24)
			elseif level[i][i2] == 2 then
				spriteBatch:addq(r_star_q, (i - 1)*24, (i2 - 1)*24)
			elseif level[i][i2] == 3 then
				spriteBatch:addq(g_star_q, (i - 1)*24, (i2 - 1)*24)
			elseif level[i][i2] == 4 then
				spriteBatch:addq(explos_q, (i2 - 1)*24, (i - 1)*24)
			elseif level[i][i2] == 5 then
				spriteBatch:addq(invdot_q, (i2 - 1)*24, (i - 1)*24)
			end
		end
	end
end

function love.draw()
	love.graphics.draw(spriteBatch, 0, 0)
end
The problem is the only thing that shows up is a few random sprites down the left side of the screen and across the top, not across the whole screen.
Please help :S (I am such a newbie) thanks in advance, Kyle.
LÖVE dem beats
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Level Generation

Post by Plu »

Just a guess but could it be related to

Code: Select all

spriteBatch = love.graphics.newSpriteBatch(tileset, 25)
limiting you to only 25 elements in the batch?
User avatar
kylewatson98
Prole
Posts: 13
Joined: Thu Feb 28, 2013 9:02 pm

Re: Level Generation

Post by kylewatson98 »

Aha thanks, guess I just needed an extra pair of eyes to skim over it :) I haven't got any mates who know Love :/
Oh well, thanks :3 This community is awesome so far!
LÖVE dem beats
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests