barodapride Posted January 31, 2014 Share Posted January 31, 2014 Does anyone understand the following function from the tanks example:function bulletHitPlayer (tank, bullet) { bullet.kill();} This function is called here: game.physics.collide(enemyBullets, tank, bulletHitPlayer, null, this); Where does bulletHitPlayer get its parameters? Link to comment Share on other sites More sharing options...
XekeDeath Posted January 31, 2014 Share Posted January 31, 2014 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. plicatibu 1 Link to comment Share on other sites More sharing options...
jerome Posted January 31, 2014 Share Posted January 31, 2014 http://docs.phaser.io/Phaser.Physics.Arcade.html#toc22 bulletHitPlayer function is called and gets enenmyBullets and tank as parameters Link to comment Share on other sites More sharing options...
Recommended Posts