O'Reilly logo

iOS 7 Game Development by Dmitry Volevodz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a score label

The next thing we need to have in our game is a label that shows how far we have gone. First, add two new properties to ERGMyScene.h:

@property (strong, nonatomic) SKLabelNode *scoreLabel;
@property (assign) double score;

After this, add a new label and actions for it in the scene initWithSize: method:

 self.score = 0; self.scoreLabel = [[SKLabelNode alloc] initWithFontNamed:@"Chalkduster"]; self.scoreLabel.fontSize = 15; self.scoreLabel.color = [UIColor whiteColor]; self.scoreLabel.position = CGPointMake(20, 300); self.scoreLabel.zPosition = 100; [self addChild:self.scoreLabel]; SKAction *tempAction = [SKAction runBlock:^{ self.scoreLabel.text = [NSString stringWithFormat:@"%3.0f", self.score]; }]; SKAction *waitAction = [SKAction ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required