Stackoverflow的新手,如果我发错了,抱歉!谢谢

“我的应用”是一个有时间限制的迷宫游戏,一旦时间到达0,游戏便会结束并转到屏幕上的游戏(单独的快速文件),其中包含一个“重播”按钮,当按下该按钮时,仅显示gamecene.sks文件而不是gamecene.swift文件(因此所有功能均无效)。有办法显示两者吗?

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
            for touch: AnyObject in touches {
                let location = touch.locationInNode(self)
                let node = self.nodeAtPoint(location) //1
                if node.name == "replay" { //2

                    let reveal : SKTransition = SKTransition.flipHorizontalWithDuration(1)
                    let scene = GameScene(size: self.size)
                    scene.scaleMode = .AspectFill
                    self.view?.presentScene(scene, transition: reveal)

                    let reveal2 : SKTransition = SKTransition.flipHorizontalWithDuration(1)
                    let sksScene = SKScene(fileNamed: "GameScene.sks")
                    sksScene!.scaleMode = .AspectFill
                    self.view?.presentScene(sksScene!, transition: reveal2)


                }
            }
        }

最佳答案

您需要确保在加载GameScene.sks时使用GameScene子类。

let skView = self.view as SKView!
let transition = SKTransition.flipHorizontalWithDuration(0.5)
let scene = GameScene(fileNamed:"GameScene") as GameScene!
scene.scaleMode = .AspectFill
skView.presentScene(scene, transition: transition)


您只需要使用presentScene一次:]

10-08 06:08