I'm trying to make a train track switching game and I've successfully drawn bezier paths and converted them to CGPath so that I can use SpriteKit's SKAction:
follow(_:asOffset:orientToPath:speed:)
This works fine for following any track (path) with orientation to the path for free. If my game had a single track that would be fine but I want to have railway switches to change tracks.
I drew the tracks so that they overlap on the straight and then branch off down the line. I figured I could switch tracks by checking if my sprite is on the overlapping path and make it follow the new path. Of course, this was naive and I only know how to use the "follow" action to follow a path from the start of the path, not from wherever my sprite happens to be. Redrawing the path as a subpath with the travelled path subtracted seems as difficult as the problem I'm currently tackling.
I'm beginning to think updating the sprite's position from
func update(_ currentTime: TimeInterval)
Does CGPath allow me to get an x coordinate for a given y on the path that I can update manually? Incidentally, I know I would lose path orientation with this method but I can ask another question about that.