Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has SpriteKit's coordinate system changed in Xcode 8?

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

like image 972
Kyle G Avatar asked Aug 02 '16 19:08

Kyle G


1 Answers

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.

like image 103
cc. Avatar answered Oct 30 '22 09:10

cc.