Jump to content

Nested Sprite in group ignored by collision


mhussar
 Share

Recommended Posts

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 its

not. I know the problem has something to do with how I'm attaching these sprites to the group. I assumed that since the child beam

was attached to the saucer parent which was added to the flying Saucer group that all sprites therein would be considered part of the

flyingSaucerGroup 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

 

Illustration_CollisionIssue.jpg

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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