Background shifting and Parallax scrolling

Hey there,
I’ve been working on the Background module in Skywalk : I added the ability of background shifting ( movement), and parallax scrolling.
Parallax scrolling for those who do not know about it, is the movement of layers from the background at different speeds, due to their distance from the observer. Parallax scrolling can be seen in real life as well : for example when travelling a road, you notice that its sidewalks and asphalt ground move at a higher speed than the mountains or the scenery in the background ( which move relatively slowly). I noticed that most programmers, when attempting to implement this kind of scrolling, tend to give layers different pre-defined speeds, this did not seem proper to me, I wanted to give each layer a height from the ship, and let the game engine automatically calculate the speed of the layer based on the speed of the ship. So I came up with the following formula ( I used Thalés theorem to retrieve it ) :

layerScrollingSpeed = (((maxHeight – heightFromShip) / maxLayerLevels) * shipScrollingSpeed)

Where maxHeight is a constant defining possible usable layer levels, meaning that heightFromShip must range from 0 ( layerScrollingSpeed == shipScrollingSpeed) to maxHeight ( layerScrollingSpeed == 0), this can be verified in the formula above by giving heightFromShip the value maxLayerLevels and then 0. Think of it as the height at which the layer will be so distant that it will seem like not moving.
So the game in its actual state looks like that :

Hope you like it !

Actual lines of code : 4112


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s