我试图让节点执行动作,然后在触摸按钮后进行场景转换。
这是我到目前为止所拥有的:
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 :(得分: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]))
}