LoginSignup
3
3

More than 5 years have passed since last update.

SpriteKit入門 -3-

Last updated at Posted at 2013-10-18

前回のSKLabelNodeのpositionプロパティの指定が気になったので調べてみました。

こんなふうにpositionを指定していましたね。

HelloScene.m
- (SKLabelNode *)newHelloNode
{
    SKLabelNode *helloNode = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
    helloNode.text = @"Hello, World!";
    helloNode.fontSize = 42;
    helloNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
    return helloNode;
}

SKLabelNodeクラスのリファレンスがこちらになります。
SKLabelNode Class Reference

ここのhorizontalAlignmentModeプロパティを見ると、positionの水平方向の配置にはデフォルトでSKLabelHorizontalAlignmentModeCenterが設定されているようです。

horizontalAlignmentMode
(略)
The possible values for this property are listed in “Text Horizontal Alignment Modes”. The default value of this property is SKLabelHorizontalAlignmentModeCenter.

つまり、positionで指定した水平方向の座標は、SKLabelNodeインスタンスの真ん中に対応するということです。
だから前回のpositionでシーンの中心座標を指定したことにより、SKLabelNodeインスタンスも画面の真ん中に表示されていたんですね。

今回はここまで。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3