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:
Xcode 8:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With