Aligning Label Nodes Within Groups

To match the design of our HUD, we need two parent nodes as groups to hold the title and value labels for the score and the elapsed time. Let’s start by building the first group, and you’ll learn how to align text label nodes inside it. We’ll create an empty node as the score group and then add the two label nodes as children. We’ll add an ‑init method to the top of the implementation in RCWHUDNode.m.

05-HUD/step02/SpaceRun/RCWHUDNode.m
 
- (instancetype)init
 
{
 
if​ (self = [super init]) {
 
SKNode *scoreGroup = [SKNode node];
 
scoreGroup.name = @​"scoreGroup"​;
 
SKLabelNode *scoreTitle =
 
[SKLabelNode labelNodeWithFontNamed:@​"AvenirNext-Medium"​];
 
scoreTitle.fontSize = 12;
 
scoreTitle.fontColor = ...

Get Build iOS Games with Sprite Kit 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.