Jump to content

Motion Path on Graphics


JokerJESUS
 Share

Recommended Posts

Hello, i made tileset, and did pathfinder for it. But now how can i do that sprites, or groups of sprites will move on this path.

my code for path:

 

I used graphics -> lineTo for making path.

function pathfinder(array){
	
	var x = groupDisable.children[0].x;
	var y = groupDisable.children[0].y;
	
	graph = game.add.graphics();
	graph.lineStyle(1, 0xffd900, 1);
	
	graph.moveTo(x,y);
	
for(var i = 0; i < groupDisable.length; i++){
	
	groupDisable.forEach(function(arg){
		if(x + 32 == arg.x && y == arg.y && !arg.checked){
			console.log('->');
			x = arg.x;
			y = arg.y;
			arg.checked = 1;
			graph.lineTo(x, y);
		}else if(x == arg.x && y + 32 == arg.y && !arg.checked){
			console.log('\\/');
			x = arg.x;
			y = arg.y;
			arg.checked = 1;
			graph.lineTo(x, y);
			console.log('argX: '+arg.x+' argY: '+arg.y+' x: '+x+' y: '+y);
		}else if(x - 32 == arg.x && y == arg.y && !arg.checked){
			console.log('<-');
			x = arg.x;
			y = arg.y;
			arg.checked = 1;
			graph.lineTo(x, y);
		}else if(x == arg.x && y - 32 == arg.y && !arg.checked){
			console.log('/\\');
			x = arg.x;
			y = arg.y;
			arg.checked = 1;
			graph.lineTo(x, y);
		}
	});

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...