停止 运行 SKAction - Sprite Kit

Stopping an running SKAction - Sprite Kit

以下代码将为旋转设置动画。

let something:SKSpriteNode = SKSpriteNode()

func start(){
  let rotateAction = SKAction.rotateToAngle(CGFloat(M_PI), duration: 10.0)
  something.runAction(SKAction.sequence([rotateAction]))
}

现在我想在动画持续时间内停止动画。有没有类似下面的?我想在用户触摸屏幕时停止动画。

func stop(){
  something.SKAction.stop()
}

首先,运行带有键的操作,以便您稍后识别:

something.runAction(rotateAction, withKey: "rotate action")

然后你可以稍后调用

来停止它
something.removeActionForKey("rotate action")

或者,您也可以删除所有操作

something.removeAllActions()

您只需使用其中之一:

  1. something.paused = false // or true 暂停节点上的操作
  2. something.removeAllActions() 明确删除与节点关联的操作
  3. 启动时命名您的操作 something.runAction(action,withKey:"action1") 然后 something.removeActionForKey("action1") 删除给定操作

如果需要,您也可以更改速度。