Page 1 of 1

Parallax Help

Posted: Sat Jul 12, 2014 3:26 am
by Maskeddog
Hello!
I am a little new to love2d, and i wanted to start to learn how to parallax, does anyone know a good tutorial, or were I should start to learn?

Re: Parallax Help

Posted: Sat Jul 12, 2014 4:02 am
by HugoBDesigner
Parallax scrolling is relatively easy to add. For each layer of background you multiply the scrolling factor by a greater number. For example, let's suppose you have a "scroll" variable that is relative to the player position. Let's also suppose you have a table with your layers of background, from the closest to the furthest:

Code: Select all

for i = #backgrounds, 1, -1 do
    local newScroll = scroll-(#backgrounds-i)*10
    love.graphics.draw(backgrounds[i], newScroll, 0)
end

Re: Parallax Help

Posted: Sat Jul 12, 2014 4:06 am
by Maskeddog
HugoBDesigner wrote:Parallax scrolling is relatively easy to add. For each layer of background you multiply the scrolling factor by a greater number. For example, let's suppose you have a "scroll" variable that is relative to the player position. Let's also suppose you have a table with your layers of background, from the closest to the furthest:

Code: Select all

for i = #backgrounds, 1, -1 do
    local newScroll = scroll-(#backgrounds-i)*10
    love.graphics.draw(backgrounds[i], newScroll, 0)
end
Oh, sweet, thanks a bunch!