Search the Community
Showing results for tags 'sprite movement over time'.
-
I use easystarJS and the PhaserPlugin to generate coordinates for pathfinding. This works well and I've got an array called "Path" which contains every x/y coordinates that a sprite should be moved to. The pathfinding "Event" fires 1 time when clicking on a map layer. some code: this.findPathTo = function(tilex, tiley) { pathfinder.setCallbackFunction(function(path) { //callback with path var path = path; //path array with ever x / y coordinate for every tile to walk over for (var i = 0, ilen = path.length; i < ilen; i++){ var num = i;/* setTimeout(function(){// This is a bad idear, what to put here? console.log(path[num]); reference.DBugger.x = path[num].x * 20; reference.DBugger.y = path[num].y * 20; }, 100);*/ } }); pathfinder.preparePathCalculation([0,0], [tilex,tiley]); //pathfinding functions pathfinder.calculatePath(); //pathfinding functions }What I want to achieve is that the Sprite => reference.DBugger (Sprite for testing) moves through all the coordinates in that array piece by piece. If I uncomment that function atop, the sprite is already at the position were I have clicked. The best way would be some function that checks when the sprite has reached path[0] coordinates and then applies path[1] coordination and so on. any suggestions? kind regards
- 1 reply
-
- pathfinding
- sprite movement over time
- (and 4 more)