Having Trouble With 2 Independent Backgrounds

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
HJW012
Prole
Posts: 8
Joined: Tue Sep 03, 2013 9:50 pm

Having Trouble With 2 Independent Backgrounds

Post by HJW012 »

Game.love
(5.31 MiB) Downloaded 136 times
In a game I am attempting to create, I plan on having a background that moves in a linear way directly in relation to the player's movement. Behind that, I plan on having a background that moves quite slowly in comparrison to the player's movement. This is to simulate a background that is a substantial distance away. I was just wondering how I should go about doing this. I have thought about having it move directly with the push of the movement buttons but that was not successful. Any ideas are welcome. Thank you.

Ps. If you are unsure of what I mean by this background, the game 'Guacamelee' is a perfect example.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Having Trouble With 2 Independent Backgrounds

Post by micha »

This type of background scrolling is called parallax scrolling.

Usually you implement that by having a fixed ration of the two backgrounds scrolling speed, say 2.
So somewhere you store how far the background has moved (in pixels) for the second background, simply divide this distance by the above factor (2) and use this distance as displacement for the second background (the one farther away).

So if for example the front background moved 100 pixels, move the other one only 50 pixels.
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests