How can I have an SKSpriteNode follow the same path back and forth?

My code is compartmentalized over many files, so I hope I can describe this easily.

I have a path that goes from point A to point B
I place an SKSpriteNode at point A and execute:
Code Block
iconPath[0] = the path
SKAction.follow(iconPath[0], asOffset: false, orientToPath: false, duration: 1))

I execute that SKACtion and as I expected, my SKNode goes from point A to point B. Fine.

I'm not sure how to reverse it, I assumed from the dox that calling that same SKAction as is, would make the SKNode go from point B to A.




Answered by SergioDCQ in 663920022
Actually someone gave me an easier answer on StackOverflow. This is a quote from the link below

There is a method called reversed() which you could use.
Below I have given your action a name of "youraction"
Code Block
let youraction = SKAction.follow(iconPath0, asOffset: false, orientToPath: false, duration: 1)
let reverseaction = SKAction.reversed(youraction)
yourspritenode.run(reverseaction)

Alternatively, you can just use reversed after the action name to run it in reverse:
Code Block
yourspritenode.run(youraction.reversed())


https://stackoverflow.com/questions/66354936/how-can-i-have-an-skspritenode-follow-the-same-path-back-and-forth/66357189#66357189
You created an action to go from A to B. Create a second action to go from B to A. Create an SKAction sequence with the two actions and run the sequence.

Code Block
let sequence = SKAction.sequence([firstAction, secondAction])
sprite.run(sequence)

firstAction and secondAction are the actions you created to move from A to B and B to A. sprite is the sprite node to move with the action sequence.

Accepted Answer
Actually someone gave me an easier answer on StackOverflow. This is a quote from the link below

There is a method called reversed() which you could use.
Below I have given your action a name of "youraction"
Code Block
let youraction = SKAction.follow(iconPath0, asOffset: false, orientToPath: false, duration: 1)
let reverseaction = SKAction.reversed(youraction)
yourspritenode.run(reverseaction)

Alternatively, you can just use reversed after the action name to run it in reverse:
Code Block
yourspritenode.run(youraction.reversed())


https://stackoverflow.com/questions/66354936/how-can-i-have-an-skspritenode-follow-the-same-path-back-and-forth/66357189#66357189
How can I have an SKSpriteNode follow the same path back and forth?
 
 
Q