O'Reilly logo

Cocos2d-x Game Development Essentials by Gareth Jones, Arutosh Gurung, Frahaan Hussain

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 Game sprites

Unlike in the previous backgrounds, the Game scene's background will be moving, providing a scrolling effect. Before you dive into the background code, an update function needs to be scheduled to be called in every frame using the following steps:

  1. Schedule the update function in the init() method using the following code:
    this->scheduleUpdate();
  2. Declare the update function in the GameScene.h file using the following code:
    void update(float dt);
  3. Implement the update function in the GameScene.cpp file using the following code:
    void GameScreen::update(float dt)
    {
    
    }

The update function is used to handle the game's logic and takes a float parameter called delta time, which is the time between frames. As all devices are not capable ...

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