1

有人可以给我一个如何使用 SKLabelHorizo​​ntalAlignmentMode 的例子吗?

这是我定义标签的方式:

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];

谢谢,有钱

4

2 回答 2

4

首先创建一个标签:

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

现在,您可以将标签与以下内容对齐:

 scoreLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;

或者

scoreLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeRight;

或者

scoreLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeLeft;

该输出如下图所示:

在此处输入图像描述

继续编码...... :)

于 2014-08-06T16:35:59.373 回答
0

还没有回答,我只是在自己寻找这个......见第二行......垂直对齐的工作方式相同。

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];
于 2014-03-12T21:21:01.537 回答