Adding the scrolling layer class
Let's add some scrolling background now, as the game looks very boring with a lifeless static image in the background. Before we actually add the code for scrolling backgrounds, let's first understand how this effect is created in games.
A scrolling background effect is added to:
Create a moving animation so that the scene doesn't look static
Create a depth of field effect to the player
This is usually created by placing two images adjacent to each other and moving both images in a particular direction. When an image goes off the screen, it is replaced at the end by the adjacent image. The width of the images has to be the same as the width of the screen.
Take a look at the following screenshot:
The blue area is the background image, which will be stationary. Then, each image that we want to scroll will be created as a separate image; a duplicated form of it will be created and placed at the width of the first image. The green hill that you see here is not one...