The following code will animate a rotation.
以下代码将为旋转设置动画。
let something:SKSpriteNode = SKSpriteNode()
func start(){
let rotateAction = SKAction.rotateToAngle(CGFloat(M_PI), duration: 10.0)
something.runAction(SKAction.sequence([rotateAction]))
}
Now I want to stop the animation within the animating duration. Is there anything similar to the following? I want to stop the animation when the user touches the screen.
现在我想在动画持续时间内停止动画。有什么类似的以下内容吗?我想在用户触摸屏幕时停止动画。
func stop(){
something.SKAction.stop()
}
2 个解决方案
#1
12
You just have to use either:
你只需要使用:
-
something.paused = false // or true
to pause actions on the node - something.paused = false //或true表示暂停节点上的操作
-
something.removeAllActions()
to definitely remove actions associated to the node - something.removeAllActions()肯定删除与节点关联的操作
- name your action when launching
something.runAction(action,withKey:"action1")
and thensomething.removeActionForKey("action1")
to remove a given action - 在启动something.runAction(action,withKey:“action1”)然后something.removeActionForKey(“action1”)删除给定的动作时命名你的动作
You may also change the speed if needed.
如果需要,您也可以更改速度。
#2
2
Firstly, run the action with a key so you can identify it later:
首先,使用密钥运行操作,以便稍后识别:
something.runAction(rotateAction, withKey: "rotate action")
Then you can stop it later by calling
然后你可以通过打电话来阻止它
something.removeActionForKey("rotate action")
Alternatively, you can remove all actions also
或者,您也可以删除所有操作
something.removeAllActions()
#1
12
You just have to use either:
你只需要使用:
-
something.paused = false // or true
to pause actions on the node - something.paused = false //或true表示暂停节点上的操作
-
something.removeAllActions()
to definitely remove actions associated to the node - something.removeAllActions()肯定删除与节点关联的操作
- name your action when launching
something.runAction(action,withKey:"action1")
and thensomething.removeActionForKey("action1")
to remove a given action - 在启动something.runAction(action,withKey:“action1”)然后something.removeActionForKey(“action1”)删除给定的动作时命名你的动作
You may also change the speed if needed.
如果需要,您也可以更改速度。
#2
2
Firstly, run the action with a key so you can identify it later:
首先,使用密钥运行操作,以便稍后识别:
something.runAction(rotateAction, withKey: "rotate action")
Then you can stop it later by calling
然后你可以通过打电话来阻止它
something.removeActionForKey("rotate action")
Alternatively, you can remove all actions also
或者,您也可以删除所有操作
something.removeAllActions()