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
I am also really tired so, maybe it's just really obvious:P
Thanks!