4
votes

I have an SKShape node that represents an ellipse. A player is placed on the current point of a Bezier Path that is based on the ellipse's CGPath:

enter image description here

I have two actions that the player node can perform. The player can either follow the path clockwise or counterclockwise.

rotateCounterClockwiseAction = SKAction.followPath(counterClockwisePath.CGPath, asOffset: false, orientToPath: true, duration: 1)
rotateClockwiseAction = SKAction.followPath(clockwisePath.CGPath, asOffset: false, orientToPath: true, duration: 1)

When I start one of the actions as:

player.runAction(SKAction.repeatActionForever(rotateClockwiseAction), withKey: "ClockwiseRotation")

The player moves along the appropriate path and direction. When I stop one of the actions:

player.removeActionForKey("ClockwiseRotation")

The player stops on the path where it was last moved to. I want to be able to start either of the actions from the player's current point, and follow the same path, but right now, if I start either one of the actions again (after an action has already been started and stopped) the player jumps to the same starting point as seen in the picture and follows the path from there. How can I get the player to follow the path from the point that it is already at?

1
you would have to create a new cgpath, same shape but starting with the point the player is atLearnCocos2D
I created my path with let ellipse = SKShapeNode (ellipseOfSize: CGSizeMake(size.0, size.1)), ie. not much experience in this area. Do you have some resource that might help me achieve this specifically?JuJoDi

1 Answers

0
votes

You can achieve this easily by using the speed property of SKNode.

Instead of removing and recreating the action, you can pause and resume it by adjusting the speed value. This will cause your bezier path animation to resume from its current position.

// Set the player node's speed to 0.0 causing all actions to be paused.
[playerNode setSpeed:0.0];

...

// Then when you're ready to resume set the player node's speed back to 1.0.
// This will cause the action to continue from its current position.
[playerNode setSpeed:1.0];