Time for action – updating labels
Let's go ahead and add the code to keep the current game stats and display them using labels:
- Create a new group called
Common
. - Right-click on this group and click on New File; it will be Objective-C class. Name it
GameStats
and make it a subclass ofNSObject
. Save the file. - 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;
- Then open the
GameStats.m
file and add theinit
method:-(instancetype)init { if (self = [super init]) { self.score = 0; self.birdsLeft = 0; self.lives = 0; } return self; }
- Open the
HUDLayer.h
file and import theGameStats.h
header at the top, like this:#import ...
Get Learning iPhone Game Development with Cocos2D 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.