roycocup Posted May 12, 2016 Share Posted May 12, 2016 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 More sharing options...
drhayes Posted May 13, 2016 Share Posted May 13, 2016 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 More sharing options...
roycocup Posted May 13, 2016 Author Share Posted May 13, 2016 Thanks! That did the trick. I'm still struggling to understand why it positions itself on a random corner of the player when I set the coorsd to 0,0 but it definitely works! Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts