2016-05-27 54 views
1

我試圖讓一個節點執行一個動作,然後在按下按鈕之後進行場景轉換。Skaction其次是場景轉換

這是我到目前爲止有:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { 
    var touch = touches as! Set<UITouch> 
    var location = touch.first!.locationInNode(self) 
    var node = self.nodeAtPoint(location) 
    var action = SKAction.moveToY(PlayButton.position.y + self.size.height, duration: 5) 

    // If next button is touched, start transition to second scene 
    if (node.name == "Balloon") { 
     PlayButton.runAction(action) 
     var secondScene = Scene2(size: self.size) 
     var transition = SKTransition.flipVerticalWithDuration(1.0) 
     secondScene.scaleMode = SKSceneScaleMode.AspectFill 
     self.scene!.view?.presentScene(secondScene, transition: transition)} 


} 

當我點擊使用模擬器不執行動作場景轉換按鈕。

回答

0

您需要將序列操作與塊操作一起使用。創建一個塊動作來處理場景轉換,如下所示:

if (node.name == "Balloon") { 
     let sceneAction = SKAction.runBlock({ 
      let secondScene = Scene2(size: self.size) 
      let transition = SKTransition.flipVerticalWithDuration(1.0) 
      secondScene.scaleMode = SKSceneScaleMode.AspectFill 
      self.scene!.view?.presentScene(secondScene, transition: transition)} 
     }) 
     playButton.runAction(SKAction.sequence([action, sceneAction])) 
} 
+0

謝謝!很棒 – Yraw