Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – adding a tutorial


Let's move back to our createGameScreen method.

  1. Inside that method, add the following lines to create our Label object:

    _tutorialLabel = Label::createWithTTF("", "fonts/Times.ttf", 60);
    _tutorialLabel->setPosition(Vec2 (_screenSize.width *  0.5f, _screenSize.height * 0.6f) );
    this->addChild(_tutorialLabel, kForeground);
    _tutorialLabel->setVisible(false);
  2. We add four states to our enumerated list of game states. These will represent the different steps in our tutorial:

    typedef enum {
      kGameIntro,
      kGamePlay,
      kGameOver,
      kGameTutorial,
      kGameTutorialJump,
      kGameTutorialFloat,
      kGameTutorialDrop
    
    } GameState;

    The first tutorial state, kGameTutorial, acts as a separator from all other game states. So, if the value for _state is greater than kGameTutorial, we are in tutorial mode.

    Now, depending on the mode, we display a different message and we wait on a different condition to change to a new tutorial state.

  3. If you recall, our showTutorial method...