mhussar Posted May 19, 2015 Share Posted May 19, 2015 Hi All, I've searched this forum and the internet in general regarding my issue but can't find a solution. I'm adding one sprite (beam as in tractor beam) as a child to another sprite (saucer, as in flying saucer) and then adding this composite sprite to a group (flyingSaucerGroup). I add x number of these composite sprites (saucer and accompanying child beam) to this group in a for loop. I have another group of sprites (squirrelGroup) which contain the squirrels that are being abducted by the flying saucers. In the update function I have this line of code : this.physics.arcade.overlap( this.squirrelGroup, this.flyingSaucerGroup, this.collisionAbduct, null, this);When a beam from a flying saucer overlaps a squirrel, I expected that the callback function (this.collisionAbduct) would be triggered but itsnot. I know the problem has something to do with how I'm attaching these sprites to the group. I assumed that since the child beamwas attached to the saucer parent which was added to the flying Saucer group that all sprites therein would be considered part of theflyingSaucerGroup that is being checked for collisions. Here is the callback code so you can see there is nothing funky going on there: collisionAbduct: function(s, { var txt = this.add.text(this.world.centerX, this.world.centerY,"squirrel killed" ); s.kill(); },Please take a look at the actual pertinent code and screen shot below.Thank you in advance for any help! Best,Michael Link to comment Share on other sites More sharing options...
mhussar Posted May 21, 2015 Author Share Posted May 21, 2015 Hi All, after more research I'm wondering if the problem has to do with collisions not working recursively? If this is true, can someone suggest a work around? ThanksMichael Link to comment Share on other sites More sharing options...
drhayes Posted May 22, 2015 Share Posted May 22, 2015 From the documentation of Arcade.Physics#collide: NOTE: This function is not recursive, and will not test against children of objects passed (i.e. Groups or Tilemaps within other Groups). I think you're going to have to track the beams individually in an array, separate from their parent group, and pass that array to Physics#collide. mhussar 1 Link to comment Share on other sites More sharing options...
mhussar Posted May 22, 2015 Author Share Posted May 22, 2015 Thanks so much for the reply! I'm glad you suggested using an array because that's how I decided to try to solve the problem but I wasn't sure if there was a better way. Link to comment Share on other sites More sharing options...
Recommended Posts