user3358306
user3358306

Reputation: 187

Stopping Repeat Actions Spritekit

Here is my code:

rotateClockWise = [SKAction rotateByAngle:-M_PI duration:skRand(0, 2.5)];

rotateClockWise = [SKAction repeatActionForever:rotateClockWise];
[asteroid1 runAction:rotateClockWise];

Is there a way to stop the rotateClockWise action?

Upvotes: 1

Views: 1848

Answers (3)

Hossam Ghareeb
Hossam Ghareeb

Reputation: 7123

In Swift

asteroid1.runAction(action, withKey: "actionKey")
asteroid1.removeActionForKey("actionKey")

Upvotes: 3

John Riselvato
John Riselvato

Reputation: 12904

also [asteroid1 removeAllActions]; will work if that's the only action you're asteroid1 has.

Ends and removes all actions from the node.

more here

Upvotes: 0

Ilario
Ilario

Reputation: 6079

you should give a Key to an action:

[asteroid1 runAction:rotateClockWise withKey:@"rotateClock"];

and after you can stop this action in this way:

[asteroid1 removeActionForKey:@"rotateClock"];

Upvotes: 2

Related Questions