Parallax Help

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Maskeddog
Prole
Posts: 2
Joined: Sat Jul 12, 2014 3:23 am

Parallax Help

Post 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?
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: Parallax Help

Post 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
@HugoBDesigner - Twitter
HugoBDesigner - Blog
Maskeddog
Prole
Posts: 2
Joined: Sat Jul 12, 2014 3:23 am

Re: Parallax Help

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

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests