Swift 斯威夫特精灵从一个游戏场景移动到另一个游戏场景

Swift 斯威夫特精灵从一个游戏场景移动到另一个游戏场景,swift,sprite-kit,skspritenode,skscene,Swift,Sprite Kit,Skspritenode,Skscene,我是斯威夫特和斯克里特的新手 我在我的第一类游戏场景中添加了一个按钮:SKScene。点击按钮后,我想移动到我的新游戏场景。我怎样才能做到这一点 我有覆盖func touchesbeagin的方法(touchs:NSSet,withEvent-event:UIEvent){ ... } 我的答案摘自Ray Wenderlich教程: SKTransition *reveal = [SKTransition flipHorizontalWithDuration:0.5]; SKScene * my

我是斯威夫特和斯克里特的新手

我在我的第一类游戏场景中添加了一个按钮:SKScene。点击按钮后,我想移动到我的新游戏场景。我怎样才能做到这一点

我有覆盖func touchesbeagin的方法(touchs:NSSet,withEvent-event:UIEvent){ ... }

我的答案摘自Ray Wenderlich教程:

SKTransition *reveal = [SKTransition flipHorizontalWithDuration:0.5];
SKScene * myScene = [[YourSceneName alloc] initWithSize:self.size];
[self.view presentScene:myScene transition: reveal];
这不是swift,但仍应适用于您的代码

YourSceneName应该是要过渡到的场景的名称。记住在您希望从中调用它的类中导入头


要制作一个按钮,只需创建一个SKSpriteNode,在touchesBegind或End中,检查触摸位置是否在spriteNode内。如果是,请执行上面发布的代码。

meisenman对Swift 2.0的回答

let reveal = SKTransition.flipHorizontalWithDuration(0.5)
let gameOverScene = GameOverScene(size: self.size)
self.view?.presentScene(gameOverScene, transition: reveal)
  • 第一个场景是游戏场景
  • 新场景名称为NewGameSecene
代码:

override func touchesBegin(touches:NSSet, withEvent event: UIEvent) {
    let reveal = SKTransition.flipHorizontalWithDuration(1.0) 
    // the number is the duration time.  After you type . right behind SKTransition, you can choose other scene transition effect. 
    self.view?presentScene(NewGameScene,transition:reveal)
}