6

In previous version of SpriteKit the origin (0,0) was always in the bottom left. Furthermore, Node's added to their parent, by default, started there.

It seems that starting with Xcode 8, the new default origin is in the center of the screen.

Is this correct behavior, a bug in the beta, or do I simply not understand SpriteKit?

The same code is being used for both

import SpriteKit
import GameplayKit

class GameScene: SKScene {   
    override func didMove(to view: SKView) {
        let ship = SKSpriteNode(imageNamed: "Spaceship")
        addChild(ship)
    }
}

Xcode 7:

enter image description here

Xcode 8:

enter image description here

Kyle G
  • 4,347
  • 4
  • 26
  • 39

1 Answers1

6

No, SpriteKit still uses the same coordinate system.

The difference is that the example .sks scene file that is provided with a new project has changed. In earlier versions of Xcode, that .sks file had its anchor point (i.e., where the "origin" of the scene is located) at (0,0), which causes the origin to be in the lower left corner.

In Xcode 8, the .sks file has a default anchor point of (0.5, 0.5), which is the center of the scene.

To get back the old behavior, just go into that .sks file and reset the anchor point to (0,0). Any legacy .sks files you have lying around should still work, since their anchor points were set to (0,0) before.

cc.
  • 3,041
  • 1
  • 21
  • 24
  • Thanks @cc I'd love to be able to confirm this, unfortunately, the latest Xcode 8 beta crashes each time I open an .sks file. I'll update as soon as I can get one open. – Kyle G Aug 02 '16 at 22:23
  • Yeah, that's a known issue, apparently - the Apple developer forums has a discussion on the topic of the .sks editor crashing. (If you bump back to beta 3, you can see the above behavior, though.) – cc. Aug 03 '16 at 22:44