Please tell me, how can I calculate the amount of distance traveled by a sprite? For example, if I use pachfinding, I need a sprite to reach the finish line three times. How do I understand that it has traveled for say 100 pixels?
Develop games in your browser. Powerful, performant & highly capable.
On every tick add the distance between previous and current location of the sprite. Then save the current location in a pair of variables.
On path found .. Sprite set prevX to self.x .. Sprite set prevY to self.y Sprite is moving along path .. Add distance(sprite.x, Sprite.y, Sprite.prevX, Sprite.prevY) to distTotal .. Sprite set prevX to self.x .. Sprite set prevY to self.y