Parallax effect: the importance of the background

The parallax effect is used in our videogame 'Robbie' to simulate a 3D environment, as you can see in the gif. Basicaly I've drawn six tiling(1) layers.

In this graph you can see all six layers used to create this parallax illusion. The further the layer, the slower it moves compared to the camera. The terrain itself it could also be considered as a layer.
The way parallax background is made is by basically moving the layers of the parallax (that are tiled horizontally) to the camera’s y position and the cameras x position divided by a specific value. The higher this value is the more it will move in relation to the camera, making it appear closer to the player. You can see this effect happening clearly when looking through the window of a moving vehicle, the closest objects move very fast while the mountains on the far back move very slowly.
``` //Sky layery("Sky", y -viewhhalf); layerx("Sky", x - viewwhalf);
//Layer 1 if (layerexists(b1id)){ layery(b1id, y-viewhhalf); layerx(b1id, x/b1depth - global.timer * 0.2); } //Layer 2 if (layerexists(b2id)){ layery(b2id, y-viewhhalf); layerx(b2id, x/b2depth) ; }
//Layer 3 if (layerexists(b3id)){ layery(b3id, y-viewhhalf); layerx(b3id, x/b3depth + global.timer * 0.15); } //Layer 4 if (layerexists(b4id)){ layery(b4id, y-viewhhalf); layerx(b4id, x/b4depth); } //Layer 5 if (layerexists(b5id)){ layery(b5id, y-viewhhalf); layerx(b5id, x/b5_depth); } ```
The layers in the graph are cropped to give a better view. Most of them, such as the buildings or clouds are indeed from 3 to 4 times longer horizontally, as you can see here:



(1): Tiling means that a certain object is designed so it can be stacked (vertically or horizontally) and it looks continuos. All layers used in Robbie are tileable.
If this post was interesting to you please consider passing by and trying our game out if you have time, thank you! :) https://ldjam.com/events/ludum-dare/45/robbie
-@paude