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 ...

Get Learning Cocos2d-x Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.