SpriteKit过渡到场景的最佳方式

时间:2015-10-29 21:01:32

标签: ios swift sprite-kit

我想实现一个菜单场景,然后在新场景中启动游戏。以下是我的解决方案,但我想知道这是否是达到预期效果的首选方式,或者是否有其他人有任何替代方案。

GameScene.swift

 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
    {
        let gameScene = MainGameScene(fileNamed: "MainGameScene")
        gameScene?.initMenuScene(self)
        let transition = SKTransition.doorwayWithDuration(1.0)

        self.view?.presentScene(gameScene!, transition: transition)
    }

MainGameScene.swift

class MainGameScene: SKScene
{

var menuScene: SKScene?

func initMenuScene(scene: SKScene)
{
    self.menuScene = scene
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{
    let transition = SKTransition.doorwayWithDuration(1.0)

    self.view?.presentScene(menuScene!, transition: transition)

}

}

0 个答案:

没有答案