===== SOLVED SOLVED =====
I placed print("pause index =", savedTrainIndex)after pausing the game and got 160, e.g. I also placed print("resume index =", savedTrainIndex) before resuming and got 160 as it should be as the node was moving along the top half of the oval.
Then, as the node was moving along the bottom half of the oval, I got 90.
Here is the response I received from Apple Deve;loper Tech Support - which worked flawlessly:
When you run the follow action on a node, SpriteKit will set the position of the node to the starting position of the provided path.
The issue you are observing (when the train makes large jumps in position) is caused because of large differences in the node’s current position compared to the follow path’s starting position.
This large difference is due to a bug in your code, specifically in the closestPointInPath function, which appears to be an algorithm that tries to determine the point on the path that is closest to the current position of the node, which you then use to calculate the starting point for the new follow path.
If you replace that function with this one (which contains a naive implementation to find the closest point to the target point), you will see that the large position jumps no longer occur:
public func closestPointInPath(_ path:UIBezierPath,
toPoint:CGPoint) -> CGPoint? {
let targetPoint = toPoint
let thePoints = getPointsForPath(path)
var closestPoint = CGPoint.zero
var minDistance = CGFloat.infinity
for point in thePoints {
let distance = distanceBetween(point, targetPoint)
if distance < minDistance {
minDistance = distance
closestPoint = point
}
}
return closestPoint
}
Mr. Chistie from Apple DTS is out-of-sight awesome.
Once again, I labor for 3 weeks and DTS solves the problem in 3 days.