Calling SKAction.follow(..) causes my SKSpriteNode to rotate 90 degrees CW and not stay horizontal as it follows my UIBezierPath?

Calling SKAction.follow(..) causes my SKSpriteNode to rotate 90 degrees CW and not stay horizontal as it follows my UIBezierPath?

I have this code (within my GameViewController Class) which implements the following of a SKSpriteNode along a UIBezierPath.

=====

Please note that a brilliant contributor solved the above challenge by creating a new Class, e.g., class NewClass: NSObject. Nevertheless, I need the solution to appear in an extension of my GameViewController

=====

func createTrainPath() {
    
    trackRect = CGRect(x: tracksPosX - tracksWidth/2,
                       y: tracksPosY,
                       width: tracksWidth,
                       height: tracksHeight)
    trainPath = UIBezierPath(ovalIn: trackRect)
                  
}   // createTrainPath


func startFollowTrainPath() {
                       
    var trainAction = SKAction.follow(
                                  trainPath.cgPath,
                                  asOffset: false,
                                  orientToPath: true,
                                  speed: theSpeed)
    trainAction = SKAction.repeatForever(trainAction)
    myTrain.run(trainAction, withKey: runTrainKey)

}   // startFollowTrainPath


func stopFollowTrainPath() {
    
    guard myTrain == nil else {
        myTrain.removeAction(forKey: runTrainKey)
        savedTrainPosition = getPositionFor(myTrain, orPath: trainPath)
        return
    }
    
}   // stopFollowTrainPath

Answered by JohnLove in 795396022

-- SOLVED --

The MAGIC centers on

(a) initializing the animated GIFs for display on the “top” every time there is a newGame()

(b) re-creating the animated GIFs with GameScene’s update(..) method.

I owe my "sanity" to both @DonMag on StackOverflow and to John at Apple DTS. Two huge Atta-Boys to these blooming geniuses.

-- end SOLVED --

The Apple Docs state:
If **orientToPath** = true, the node’s **zRotation** property animates so that the node turns to follow the path. If false, the **zRotation** property of the node is unchanged.

I have initialized zRotation = 0.0 (no rotation) and to both +1.0 and -1.0 which initializes the train's zRotation accurately. But as soon as motion begins, the train immediately rotates 90 degrees on its own ??

I have been at this for a good 3-ish weeks, with total failure.

Accepted Answer

-- SOLVED --

The MAGIC centers on

(a) initializing the animated GIFs for display on the “top” every time there is a newGame()

(b) re-creating the animated GIFs with GameScene’s update(..) method.

I owe my "sanity" to both @DonMag on StackOverflow and to John at Apple DTS. Two huge Atta-Boys to these blooming geniuses.

-- end SOLVED --

Calling SKAction.follow(..) causes my SKSpriteNode to rotate 90 degrees CW and not stay horizontal as it follows my UIBezierPath?
 
 
Q