Jump to content

Binding 2 Sprites


roycocup
 Share

Recommended Posts

Hi Guys,

I was unable to find an answer to this on the forum, but please direct me there if I'm wrong.

I'm building a football game in Phaser. I'm also a bit of a newbie.

I need a way to bind the Ball sprite to the Player sprite when they collide. I looked into making them into separate groups and moving the ball to the player's group and thats all good but the ball will keep moving.

What I'm looking is for the ball to become part of the player sprite so it looks like the player is carrying the ball from then on (eventually pass, strike etc..).

Does this make sense? I can't find any examples that bind elements together, so I was just wondering if anybody has any ideas?

 

Thanks!

Rodders

Link to comment
Share on other sites

Sprites and Groups look a lot alike. They can both have children. So, yeah, when the player collides with the ball sprite you can add the ball to the player sprite and it'll move along with the player.

Don't forget to reset the ball's coordinates at that point to (0, 0) or something; its position is relative to its parent container. In the World that's probably some large-ish x and y, but in the player sprite it's relative to it.

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