backgrounds

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
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

backgrounds

Post by baconhawka7x »

In this game you're a little red box that moves around.
I'm trying to make the background follow you so that I don't have to draw it everywhere, all the time and take up a bunch of memory.

So here's my code for the background so far

Code: Select all


bg = {}
bg[1] = love.graphics.newImage('pics/bg.png')
bg[1]:setFilter('nearest','nearest')
bg.width = 16
bg.height = 16

bg.startx = 0
bg.starty = 0
bg.stretch = 10 --Height of the field
bg.length = 10-- Width of the field
function bg.draw()
	for v=bg.starty,bg.stretch do
		for i=bg.startx,bg.length do
			love.graphics.setColor(255,255,255)
			love.graphics.draw(bg[1],i * bg[1]:getWidth(),v * bg[1]:getHeight())
		end
	end
end
function bg.update(dt)
	if player.y < bg.starty + 10 then
		bg.starty = bg.starty - 10
		bg.stretch = bg.stretch - 10
	end
	if player.x < bg.startx + 10 then
		bg.startx = bg.startx - 10
		bg.length = bg.length - 10
	end
	if player.y > bg.stretch - 10 then
		bg.stretch = bg.stretch + 10
		bg.starty = bg.starty + 10
	end
	if player.x > bg.length - 10 then
		bg.length = bg.length + 10
		bg.startx = bg.startx + 10
	end
end
in bg.update it is limiting the "for" loops to only drawing near the player. Well that's what I'm trying to do anyways!:P It's not working for some reason, I'd appreciate some help!
I am also really tired so, maybe it's just really obvious:P

Thanks!
Attachments
Archive.love
Download!:D
(3.93 KiB) Downloaded 51 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests