【发布时间】:2017-02-04 21:35:40
【问题描述】:
在我的 MenuScene 中,我有一个播放按钮,如果我触摸它,它会使用以下代码更改为 GameScene:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
if atPoint(location).name == "playButton" {
let playScene = GameScene(size: self.size)
let playSceneTransition = SKTransition.fade(withDuration: 0.5)
playScene.scaleMode = SKSceneScaleMode.aspectFill
self.view?.presentScene(playScene, transition: playSceneTransition)
}
}
但 GameScene 看起来像在左下角,只显示场景的右上角。如果我在启动游戏时更改 GameViewCotroller 以显示 GameScene 而不是 MenuScene,它看起来非常好。这是为什么?去 GameScene 的代码有问题吗?
【问题讨论】:
-
可能和你的GameScene锚点属性有关,你修改了吗?
-
不,我从未更改过任何锚点属性。
-
我在这里注意到的两件事是,问题似乎(显然)来自您的 GameScene 类(因为显示其他场景不是问题),这看起来非常类似于在 (0,0) 添加带有锚点 (0.5, 0.5) 的 SKSpriteNode 时会遇到的问题。你的 GameScene 孩子是什么?
-
哦等等,我刚刚注意到我的 GameScene.sks 和 .swift 文件由于某种原因不再链接。
-
“链接”是什么意思?
标签: swift sprite-kit