简体   繁体   English

SpriteKit的坐标系在Xcode 8中有变化吗?

[英]Has SpriteKit's coordinate system changed in Xcode 8?

In previous version of SpriteKit the origin (0,0) was always in the bottom left. 在以前版本的SpriteKit中,原点(0,0)始终位于左下角。 Furthermore, Node's added to their parent, by default, started there. 此外,默认情况下,Node已添加到其父级。

It seems that starting with Xcode 8, the new default origin is in the center of the screen. 似乎从Xcode 8开始,新的默认原点位于屏幕的中心。

Is this correct behavior, a bug in the beta, or do I simply not understand SpriteKit? 这是正确的行为,测试版中的错误,还是我根本不了解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 7:

在此输入图像描述

Xcode 8: Xcode 8:

在此输入图像描述

No, SpriteKit still uses the same coordinate system. 不,SpriteKit仍然使用相同的坐标系。

The difference is that the example .sks scene file that is provided with a new project has changed. 不同之处在于,随新项目提供的示例.sks场景文件已更改。 In earlier versions of Xcode, that .sks file had its anchor point (ie, where the "origin" of the scene is located) at (0,0), which causes the origin to be in the lower left corner. 在早期版本的Xcode中,该.sks文件的锚点(即场景的“原点”所在的位置)位于(0,0),这导致原点位于左下角。

In Xcode 8, the .sks file has a default anchor point of (0.5, 0.5), which is the center of the scene. 在Xcode 8中,.sks文件的默认锚点为(0.5,0.5),这是场景的中心。

To get back the old behavior, just go into that .sks file and reset the anchor point to (0,0). 要恢复旧的行为,只需进入该.sks文件并将锚点重置为(0,0)。 Any legacy .sks files you have lying around should still work, since their anchor points were set to (0,0) before. 您所处的任何遗留.sks文件仍然有效,因为它们的锚点之前设置为(0,0)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM