Search code examples
swiftsprite-kitsklabelnode

How can I set the alignment of a SKLabelNode


I'm trying to keep the left side of an SKLabelNode fixed after updating it. The thing is that the SKLabelNode is growing in both directions. All I want is to grow only in the right side. Thanks a lot.


Solution

  • The problem is, that SKNodes have their origin in the center of their node. So you will have to set the SKLabelHorizontalAlignmentMode to "left" to resolve this problem.

    var label:SKLabelNode = SKLabelNode()
    label.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Left
    

    Here a picture, what the different modes do:

    enter image description here Link to picture origin