1

Can someone give me an example of how to use SKLabelHorizontalAlignmentMode?

Here's how I'm defining my label:

RunningLevelLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster" ];
RunningLevelLabel.text = [NSString stringWithFormat:@"%i",numberOfBonusAlienPoints];
RunningLevelLabel.fontSize = 36;
RunningLevelLabel.position = CGPointMake(-10,-50);  // offscreen
RunningLevelLabel.fontColor = [SKColor grayColor];

[StartScreenWindow addChild:RunningLevelLabel];

thanks, rich

user2887097
  • 309
  • 4
  • 12

2 Answers2

4

First create a label:

  SKLabelNode *scoreLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
  scoreLabel.text = @"00000";
  scoreLabel.fontSize  = 18;
  scoreLabel.fontColor = [UIColor blackColor];
  scoreLabel.position  = CGPointMake(200, 300);
  [self addChild: scoreLabel];

Now, you can align the label with:

 scoreLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;

OR

scoreLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeRight;

OR

scoreLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeLeft;

This outputs are shown in figure below:

enter image description here

Keep coding............. :)

Krishna Raj Salim
  • 7,331
  • 5
  • 34
  • 66
0

Hasn't been answered yet and I was just looking for this myself... See the 2nd line...vertical alignment works the same way.

SKLabelNode  *RunningLevelLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster" ];
[RunningLevelLabel setHorizontalAlignmentMode:SKLabelHorizontalAlignmentModeCenter];

RunningLevelLabel.text = [NSString stringWithFormat:@"%i",numberOfBonusAlienPoints];
RunningLevelLabel.fontSize = 36;
RunningLevelLabel.position = CGPointMake(-10,-50);  // offscreen
RunningLevelLabel.fontColor = [SKColor grayColor];
[StartScreenWindow addChild:RunningLevelLabel];
Jason
  • 70
  • 2
  • 6