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 the final screen sprites


The last sprites we need to create are the clouds, the bomb and shockwave, and our game state messages.

  1. Back to the createGameScreen method, add the clouds to the screen:

    for (int i = 0; i < 4; i++) {
      float cloud_y = i % 2 == 0 ? _screenSize.height * 0.4f : _screenSize.height * 0.5f;
      auto cloud = Sprite::createWithSpriteFrameName("cloud.png");
      cloud->setPosition(Vec2 (_screenSize.width * 0.1f + i * _screenSize.width * 0.3f,  cloud_y));
      _gameBatchNode->addChild(cloud, kBackground);
      _clouds.pushBack(cloud);
    }
  2. Create the _bomb sprite; players will grow when tapping the screen:

    _bomb = Sprite::createWithSpriteFrameName("bomb.png");
    _bomb->getTexture()->generateMipmap();
    _bomb->setVisible(false);
    
    auto size = _bomb->getContentSize();
    
    //add sparkle inside bomb sprite
    auto sparkle = Sprite::createWithSpriteFrameName("sparkle.png");
    sparkle->setPosition(Vec2(size.width * 0.72f, size.height *  0.72f));
    _bomb->addChild...