user3707671
user3707671

Reputation: 85

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

When I create a SpriteKit game from scratch using Swift, in the didMoveToView method of my GameScene I write:

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

I get back.

1024.0
768.0

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

If I add a shape to the screen to confirm what I am reading I 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 seems like I missing a fundamental part the sizing in Spritekit or iOS in general.

I am using xcode 7 beta 3 which is Swift 2.0. Although I am using Swift to code this I am not opposed to a suggestion written in Objective-C

Upvotes: 3

Views: 160

Answers (1)

Claudio D'Agostino
Claudio D'Agostino

Reputation: 115

I had a similar problem and i solved putting this into gameViewController

            scene.size = skView.bounds.size

Upvotes: 1

Related Questions