3

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

0x141E
  • 12,613
  • 2
  • 41
  • 54
user3707671
  • 85
  • 1
  • 5
  • http://stackoverflow.com/questions/25205882/dealing-with-different-ios-device-resolutions-in-spritekit – 0x141E Jul 21 '15 at 19:31

1 Answers1

1

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

            scene.size = skView.bounds.size