Train like movement in a 2D game

I am developing a 2D game using Cocos2d-X in C++ language. In my game, I need to implement train movement.

Here is the image about the output I want to achieve:

I tried to do the above moment using Actions from Cocos2d-X. However on the curved part of the tracks, the train movement is not accurate.

I have following questions:

  • Is it a right method to create the train movement using Actions? If no, which alternate methods/algorithms can be used?

  • I wanted achieve train movement similar to Mini Metro game. How to create such train movement in Cocos2D-X?

I would appreciate any suggestions/thoughts on this topic.

How do you draw the rail? If it’s made of short lines you can cheat by matching train rotation with the rail.

Otherwise take look at this.

Thank you for the reply. The curved tracks is just an image. I am able to move the single compartment along the curve using MoveTo and RotateBy action. However, the multiple compartment animation looked together is not looking like a train moving along the curved path.

Also looking at this Tween bezier curves