2014-09-19 57 views
1

我是新來的斯威夫特和SKSPRITE迅速SKSprite從一個GameScene移動到另一個

我說對我的第一類GameScene一個按鈕:SKScene。當按鈕被鎖住時,我想移動到我的新GameScene。我怎樣才能做到這一點?

我有方法重寫FUNC touchesBegin(觸摸:NSSet中,withEvent事件:的UIEvent){ ... }

回答

1

http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners

我的回答是從這個雷Wenderlich教程剝離:

SKTransition *reveal = [SKTransition flipHorizontalWithDuration:0.5]; 
SKScene * myScene = [[YourSceneName alloc] initWithSize:self.size]; 
[self.view presentScene:myScene transition: reveal]; 

這不是快捷,但仍應該與您的代碼一起工作。

YourSceneName應該是您想要轉換到的場景的名稱。記得在你想從中調用它的類中導入標題。

要創建按鈕,只需創建一個SKSpriteNode,然後在touchesBegan或Ended中檢查觸摸位置是否在spriteNode中。如果是,請執行上面的代碼。

0

meisenman對雨燕2.0

let reveal = SKTransition.flipHorizontalWithDuration(0.5) 
let gameOverScene = GameOverScene(size: self.size) 
self.view?.presentScene(gameOverScene, transition: reveal) 
0
  • 的第一個場景的答案是GameScene
  • 新場景名稱是NewGameScene

代碼:

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) 
} 
相關問題