Re: 2 backgrounds (moving) at the same time [SOLVED]
Posted: Tue Apr 15, 2014 4:31 pm
Code: Select all
if math.abs( background2x ) >= background2:getWidth() then
x = 0
end
Code: Select all
if math.abs( background2x ) >= background2:getWidth() then
x = 0
end
Well, it kinda works, but I'm not going to ask for more help, since it feels like I'm asking for too much, I'll tweak it.davisdude wrote:Code: Select all
if math.abs( background2x ) >= background2:getWidth() then x = 0 end
Code: Select all
function love.load()
background=love.graphics.newImage('space1.png')
background2=love.graphics.newImage('space2.png')
background1x = 0
background2x1 = 0
background2x2 = background2:getWidth()
dir = -16
end
function love.draw()
love.graphics.draw(background, background1x )
love.graphics.draw(background2, background2x1)
love.graphics.draw(background2, background2x2)
end
function love.update( dt )
background2x1 = background2x1 + dir * dt
background2x2 = background2x2 + dir * dt
if math.abs( background2x1 ) >= background2:getWidth() then
background2x1 = 0
background2x2 = backgrounf2:getWidth()
end
end
Didn't ask for help, but... Thank you so much!davisdude wrote:Well for smooth scrolling, you would actually need to have two background 2s. Something like thisThat should workCode: Select all
function love.load() background=love.graphics.newImage('space1.png') background2=love.graphics.newImage('space2.png') background1x = 0 background2x1 = 0 background2x2 = background2:getWidth() dir = -16 end function love.draw() love.graphics.draw(background, background1x ) love.graphics.draw(background2, background2x1) love.graphics.draw(background2, background2x2) end function love.update( dt ) background2x1 = background2x1 + dir * dt background2x2 = background2x2 + dir * dt if math.abs( background2x1 ) >= background2:getWidth() then background2x1 = 0 background2x2 = backgrounf2:getWidth() end end