Page 2 of 2

Re: 2 backgrounds (moving) at the same time [SOLVED]

Posted: Tue Apr 15, 2014 4:31 pm
by davisdude

Code: Select all

if math.abs( background2x ) >= background2:getWidth() then
    x = 0
end

Re: 2 backgrounds (moving) at the same time [SOLVED]

Posted: Tue Apr 15, 2014 4:51 pm
by ErvinGamez
davisdude wrote:

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.

Re: 2 backgrounds (moving) at the same time [SOLVED]

Posted: Tue Apr 15, 2014 6:17 pm
by davisdude
Well for smooth scrolling, you would actually need to have two background 2s. Something like this

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
That should work :)

Re: 2 backgrounds (moving) at the same time [SOLVED]

Posted: Tue Apr 15, 2014 7:42 pm
by ErvinGamez
davisdude wrote:Well for smooth scrolling, you would actually need to have two background 2s. Something like this

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
That should work :)
Didn't ask for help, but... Thank you so much!