Using collision callbacks

It's often helpful when making games to know when objects have touched, or have stopped touching. To do this, we use contact events.

Contact events
These are events that get triggered when a body touches another body. You can set the onBeginContact property of any body like this:

Where block is your object, and blockHit is your function name. This will pass 5 arguments: bodyA, bodyB, shapeA, shapeB, equation

The onEndContact property works in the same way.

Phaser's Contact Event example