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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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