如何在SpritKit Swift的SKScene中添加新的SKScene With

时间:2014-07-03 09:00:38

标签: objective-c switch-statement swift sprite-kit sprite

我必须在swift

中添加SpriteKit中的下一个SKScene
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!)
    {
        var objgamescen = GameScene()

        //objgamescen.initWithSize(self.size, playerWon: true)
        self.view .presentScene(objgamescen)
    }

然后GameScene为Blanked,Self.frame为(0.0,0.0,1.0,1.0)

2 个答案:

答案 0 :(得分:0)

SKScene中添加了多个场景由此:

let skView = self.view as SKView
        skView.showsFPS = false
        skView.showsNodeCount = false
        skView.ignoresSiblingOrder = true
        /* Set the scale mode to scale to fit the window */
        var scene: HomeScene!
        if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
            if UIScreen.mainScreen().bounds.size.width < 568 {
                scene = HomeScene(size: CGSizeMake(480, 320))
            }else {
                scene = HomeScene(size: CGSizeMake(568, 320))
            }
        }else {
            scene = HomeScene(size: CGSizeMake(1024, 768))
        }

        scene.scaleMode = .AspectFill
        skView.presentScene(scene)

答案 1 :(得分:0)

听起来你只是想重新启动场景,你可以通过创建像这样的函数来做到这一点

func goToGameScene(){
let gameScene:GameScene = GameScene(size: self.view!.bounds.size) // create your new scene
let transition = SKTransition.fadeWithDuration(1.0) // create type of transition (you can check in documentation for more transtions)
gameScene.scaleMode = SKSceneScaleMode.Fill
self.view!.presentScene(gameScene, transition: transition)
}

然后你只需将它调用到你希望它发生的地方

goToGameScene()