We will create a background movement that moves in a different speed than the runway. This is also known as parallax scrolling, and creates an illusion of depth.
Let's adjust the movement of the background with the following steps:
runway.js
file, we append the following code before the end of the tick
function:game.view.floor.style.backgroundPositionY = round * game.BACKGROUND_MOVEMENT_SPEED + 'px';
setting.js
file for easier access:game.BACKGROUND_MOVEMENT_SPEED = 5;
When we test the game in the browser, the background moves slower than the runway. This creates a perception of depth. The background appears to be far away from us.
We have completed the task by adding a background that looks like it's far away from the player and runway.
I guess you have had this experience already. Imagine you are inside a car and you are looking outside. Things nearer to you will pass by the car very fast; things that are far away seem to move slower. Things that are very far away, like the mountain in the background, do not seem to move at all:
This is because of how we see things in the perspective view. In the digital world, we call this parallax scrolling.
Therefore, when we are moving game objects around, we can make use of the speed differences to create an illusion of depth.
In our game, the background is something far away in space. The movement of the background should move much slower than the player's running speed.
The normal speed is 50. We can set the background movement speed to be 1/10 of the normal speed:
18.220.201.187