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 – texturing the buildings


There are a few changes to the way the initBlock method runs now:

  1. Each block will store references to four different types of texture, representing the four types of buildings used in the game (_tile1, _tile2, _tile3, and _tile4). So we now store that information in the initBlock method:

    void Block::initBlock() {
    
      _tile1 = SpriteFrameCache::getInstance()- >getSpriteFrameByName ("building_1.png");
      _tile2 = SpriteFrameCache::getInstance()- >getSpriteFrameByName ("building_2.png");
      _tile3 = SpriteFrameCache::getInstance()- >getSpriteFrameByName ("building_3.png");
      _tile4 = SpriteFrameCache::getInstance()- >getSpriteFrameByName ("building_4.png");
  2. Each block also stores references to two types of textures for the building roof tile (_roof1 and _roof2):

    _roof1 = SpriteFrameCache::getInstance()-> getSpriteFrameByName ("roof_1.png");
      _roof2 = SpriteFrameCache::getInstance()- >getSpriteFrameByName ("roof_2.png");
  3. Next, we create and...