The idea is to have the sprite moving from point A to point B, and then coming back to point A.
Your sprite should have an instance variable "dir" that would stand for the direction the sprite is going. (example, patroling from left to right, up to down, etc...) Naming and type of the variable is up to you (number or text).
For this example, let's consider a number, where 0 is the sprite going to the right, 1 is going to the left.
+ Is Sprite.dir = 0 ++ Is Sprite.X < destination.x => Sprite.X + 1 ++ Is Sprite.X >= destination.x => Sprite.dir = 1 => destination.x = new destination
+ Is Sprite.dir = 1 ++ Is Sprite.X > destination.x => Sprite.X - 1 ++ Is Sprite.X <= destination.x => Sprite.dir = 0 => destination.x = new destination
It is up to you the way you set your destination. You can also use the same logic to test the Y position.
Hope it is clear enough and helps you, let me know.Kyatric2011-09-11 12:57:34