Years ago I wrote a fun little puzzle game that had a train running along the tracks:
http://www.newarteest.com/games/rrailroad.html
How I did it was pretty simple. First I had a table (well an array, it wasn’t Lua) with all the coordinates of the path listed in it. What I mean is the x,y position of each intersection listed in the order that the train will pass through them.
Then I had a variable to keep track of the train’s current target. That is, which entry in the table the train was currently moving towards.
Finally, I setup an event listener that moved the train toward its target every frame. If the train is below the target add 1 to the train’s Y position, if the train is above the target subtract 1 from the train’s Y position, etc.
That listener would check how close the train was to its target, and if the target was reached the target variable would increment to the next target.
–
Maybe I should port that game to iPhone. hm… [import]uid: 12108 topic_id: 7455 reply_id: 26393[/import]