O'Reilly logo

Learning Cocos2d-x Game Development by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required