Jump to content

How to use overlap with an array of groups and a callback?


Uhfgood
 Share

Recommended Posts

I have 4 groups that I want to test my bullet group against.

 

What I noticed when it was passed a group, the callback only passes in the actual sprite that was collided.

 

I would like to know if it's the same way if I specified an array of groups -- this is the form I want to use

game.physics.arcade.overlap( bullets, [asteroidGroup1, asteroidGroup2, asteroidGroup3, asteroidGroup4], bulletAsteroidCollisionHandler, null, this );

then something like

function bulletAsteroidCollisionHandler( bullet, asteroid1, asteroid2, asteroid3, asteroid4 ){    // ...}

Will this work, and is this correct?

 

 

Link to comment
Share on other sites

What you're saying is it's only passing through the array of objects.

 

I still want to know how to use it properly.

 

Do I iterate through it to get the desired object (for instance 'for( var i = 0; i < 4; i++ ) { var object = objectArray[ i ]; }' ?

 

Also if it is a group, does that mean a single sprite is passed to the callback (so it would be 4 single sprites in an array passed to the callback?)

Link to comment
Share on other sites

The collision is being broken up into separate, distinct collision events, each with two participants. There's no "full picture" callback, but your callback will be executed for each separate collision, and will have the participating objects of that particular isolated event available.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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