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

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.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

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

Post by davisdude »

Code: Select all

if math.abs( background2x ) >= background2:getWidth() then
    x = 0
end
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
ErvinGamez
Prole
Posts: 17
Joined: Tue Apr 15, 2014 11:32 am

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

Post 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.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

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

Post 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 :)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
ErvinGamez
Prole
Posts: 17
Joined: Tue Apr 15, 2014 11:32 am

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

Post 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!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 0 guests