Jump to content

How do I detach the sprite and move it independentely?


roycocup
 Share

Recommended Posts

Hi Guys,

I have been battling with this for some time now. I'm kinda newbie with phaser too.

Currently I'm trying to build a football game where the player adds the ball (both are sprites) to his own sprite and moves around with it until is moment to "kick" the ball, sending it in any direction.

My problem is that I can't seem to be able to release the ball once its been attached. I tried "moveToXY" or "AccellerateToXY" but nothing seems to be doing it. I also tried bypassing the collision "attach" behavior as it seems that it may be a problem but I dont think that is the problem, unless someone tells me otherwise. 

Here's a screenshot of the game so you can have better context .

How can I release the ball from the sprite and send it on a given direction? What do you think is the problem?


	...
	kick: function(direction, speed){
		var ball = this.sprite.getChildAt(0);
		this.sprite.removeChildAt(0);
		game.physics.arcade.moveToXY(ball, direction.x, direction.y, speed);
		this.possession = false;
	},
	...

 

Screen Shot 2016-05-26 at 13.37.30.png

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...