Search code examples
iosswiftsprite-kitskscene

Label in SKScene not fully left justified in iPhone 6 / 6plus


I am working on ensuring a label always appears in the top-left corner of the screen regardless of what device.

Here is my code:

override func didMoveToView(view: SKView) {

        var screenSize = UIScreen.mainScreen().bounds
        var screenWidth = screenSize.width
        var screenHeight = screenSize.height


        self.scaleMode = SKSceneScaleMode.AspectFit;
        self.backgroundColor = SKColor.blackColor()
        gameScore = SKLabelNode(fontNamed: "Chalkduster")
        gameScore.text = "Score: 0"
        gameScore.position = CGPointMake(0, self.frame.size.height)
        gameScore.horizontalAlignmentMode = .Left
        gameScore.verticalAlignmentMode = .Top
        gameScore.fontSize = 48
        gameScore.zPosition = 1
        addChild(gameScore)


    }

On all iPad family devices it appears perfectly to the left, but on the iPhone 6 and 6+ it appears indented about 1/2 an inch to the right.

Any ideas why this would be?

Thanks!


Solution

  • I wanted to answer this in case other beginners like me get stuck! Be sure to read up on aspect and scaling mode.

    I had:

    self.scaleMode = SKSceneScaleMode.AspectFit;
    

    But it should be:

     self.scaleMode = SKSceneScaleMode.Fill;