Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Can someone explain this from the tanks example


barodapride
 Share

Recommended Posts

This function is the collision detection call.

game.physics.collide(enemyBullets, tank, bulletHitPlayer, null, this);

It checks for collisions between sprites in the enemyBullets group, and the tank sprite.

When it detects a collision, it calls the bulletHitPlayer function.

The null parameter can be another function (from the docs): "A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collideCallback will only be called if processCallback returns true."

The last parameter, this, is the callback context.

 

So, when a bullet hits the tank, the bulletHitPlayer function is called, and the bullet is passed in as the first parameter, and the tank is passed in as the second, because that is how they were passed into the collision detection function.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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