Jump to content

[Solved]How to create sprite follow/pin another sprite like game.debug.body???


Recommended Posts

1 hour ago, samid737 said:

you can use game.physics.arcade.moveToObject() to take care of that. An applied example :

If you want one object to always be positioned relative to another object, you can use addChild() to add one sprite as a child of the parent.


finally, I use addChild() to add the player sprite, like this , I make the graphics's element follow the user

graphics = game.add.graphics(0, 0);
graphics.beginFill(0xFF0000, 1);
player.addChild(graphics.drawCircle(0, 0, 30));


but when I move the player right left, the graphics's element  position will change.......

the graphics's element is leave the  player body, how to fix it to center, thx

I think that the scale problem is make it happen the problem............. 

	if (faceRight == true) {
			player.scale.x *= -1;
			player.anchor.x = 0.5;
			player.x = player.x - 10;
			faceRight = false;
			faceLeft = true;
            bullet_direction = 'right';


	player.body.velocity.x = -250;
		if (faceLeft == true) {
			player.scale.x *= -1;
			player.anchor.x = 0.5;
			faceLeft = false;
			faceRight = true;
            bullet_direction = 'left';


Link to comment
Share on other sites


  • Recently Browsing   0 members

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