3

I have a function that creates a path from a sprite and then runs SKAction.follow(path, duration: 1.0). The path starts at (0,0) and ends at a target point. When I create this path for each sprite and run it, they all move along the same path, but relative to their start position.

They dont follow the path from their position to the same target position for some reason, they dont converge at the end point.

What am I doing wrong?

some_id
  • 29,466
  • 62
  • 182
  • 304

1 Answers1

4

You could use the other follow path type method:

enter image description here

where offset:

If true, the points in the path are relative offsets to the node’s starting position. If false, the points in the node are absolute coordinate values.

To find more details look to the official docs


If you need to re-builds your paths to programmatically change some element (for example get all CGPathElement's from the start CGPoint to the end CGPoint) you can look to this answer

Community
  • 1
  • 1
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
  • Thanks for this, my issue was due to the target point not being relative to the sprites coordinates, with the action starting at (0, 0) – some_id Jan 27 '17 at 16:16
  • Oh, maybe related to the [conversion](https://developer.apple.com/reference/spritekit/sknode/1483056-convert) of `CGPoint` between two different nodes – Alessandro Ornano Jan 27 '17 at 16:27