Skip to Main Content
Learning iPhone Game Development with Cocos2D 3.0
book

Learning iPhone Game Development with Cocos2D 3.0

by Kirill Muzykov
June 2014
Beginner to intermediate content levelBeginner to intermediate
434 pages
9h 49m
English
Packt Publishing
Content preview from Learning iPhone Game Development with Cocos2D 3.0

Time for action – updating labels

Let's go ahead and add the code to keep the current game stats and display them using labels:

  1. Create a new group called Common.
  2. Right-click on this group and click on New File; it will be Objective-C class. Name it GameStats and make it a subclass of NSObject. Save the file.
  3. Open the GameStats.h file and add the following properties:
    @property (nonatomic, assign) int score;
    @property (nonatomic, assign) int birdsLeft;
    @property (nonatomic, assign) int lives;
  4. Then open the GameStats.m file and add the init method:
    -(instancetype)init
    {
        if (self = [super init])
        {
            self.score = 0;
            self.birdsLeft = 0;
            self.lives = 0;
        }
        
        return self;
    }
  5. Open the HUDLayer.h file and import the GameStats.h header at the top, like this:
    #import ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

James Goodwill, Wesley Matlock

Publisher Resources

ISBN: 9781782160144Supplemental Content