Why frame.size 1024x768 in portrait mode in SpriteKit?

When I create a SpriteKit game from scratch using Swift, in didMoveToView

my method I GameScene

write:

    print(frame.size.width)
    print(frame.size.height)

      

I'm coming back.

1024.0
768.0

      

My app is currently in portrait mode. I thought the frame was the smallest rectangle the node could contain.

If I add a shape to the screen to confirm that I am reading, add the following code:

anchorPoint = CGPoint(x: 0.5, y: 0.5)
let leftShape = SKShapeNode(rectOfSize: CGSize(width: frame.size.width/8, height: frame.size.height/2))
leftShape.fillColor = UIColor.redColor().colorWithAlphaComponent(0.2)
leftShape.strokeColor = UIColor.clearColor()
leftShape.name = "left"
addChild(leftShape)

      

I get the following:

enter image description here

None of this makes sense to me. The math doesn't add up. It looks like I missed the main part of the measurement in Spritekit or iOS in general.

I am using xcode 7 beta 3 which is Swift 2.0. Although I use Swift to code this, I don't mind the proposal written in Objective-C

+3


source to share


1 answer


I had a similar problem and decided to put it in gameViewController



            scene.size = skView.bounds.size

      

+1


source







All Articles