Swift 从 MainMenuScene 转换后 GameScene 将无法正确显示

GameScene won't display correctly after transition from MainMenuScene in Swift

我正在制作游戏,目前我有一个 MenuScene 和一个 GameScene。如果我自己玩 GameScene,一切都会正确显示。如果我将 MenuScene 设置为默认值,然后按开始,GameScene 就会错位。好像被稍微拖到了左下角。

我的转换代码:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        let touch = touches.first
        
        if let location = touch?.location(in: self) {
            let nodesArray = self.nodes(at: location)
            
            if nodesArray.first?.name == "newGameButton" {
                let transition = SKTransition.flipHorizontal(withDuration: 0.5)
                let gameScene = GameScene(size: self.size)
                gameScene.scaleMode = scaleMode
                self.view?.presentScene(gameScene, transition: transition)
            }
        }
    } 

搜索issue发现其他人也有同样的问题,因为他们没有设置场景模式。但是我有这个“gameScene.scaleMode = scaleMode”,我也试过“gameScene.scaleMode = .aspectFill”

我在属性检查器中对两个场景的设置相同,所以不确定我做错了什么。是程序错误还是设置错误。我已经添加了照片。任何帮助表示赞赏。谢谢。

我设法修复了它。我更改了转换代码。

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        let touch = touches.first
        
        if let location = touch?.location(in: self) {
            let nodesArray = self.nodes(at: location)
            
            if nodesArray.first?.name == "newGameButton" {
                //let gameScene = GameScene(size: self.size)
                let gameScene = GameScene(fileNamed: "GameScene")!
                let transition = SKTransition.flipHorizontal(withDuration: 0.5)
                gameScene.scaleMode = scaleMode
                self.view?.presentScene(gameScene, transition: transition)
            }
        }
    }

现在场景显示正确。希望不会导致任何其他问题。