Added Game Object level collision events

This commit is contained in:
Richard Davey 2019-12-18 02:22:37 +00:00
parent a7c644454f
commit 5cb7d8484f

View file

@ -22,6 +22,16 @@ var MatterCollisionEvents = {
var bodyA = pair.bodyA;
var bodyB = pair.bodyB;
if (bodyA.gameObject)
{
bodyA.gameObject.emit('collide', bodyA, bodyB, pair);
}
if (bodyB.gameObject)
{
bodyB.gameObject.emit('collide', bodyB, bodyA, pair);
}
matter.Events.trigger(bodyA, 'onCollide', { pair: pair });
matter.Events.trigger(bodyB, 'onCollide', { pair: pair });
@ -54,6 +64,16 @@ var MatterCollisionEvents = {
var bodyA = pair.bodyA;
var bodyB = pair.bodyB;
if (bodyA.gameObject)
{
bodyA.gameObject.emit('collideActive', bodyA, bodyB, pair);
}
if (bodyB.gameObject)
{
bodyB.gameObject.emit('collideActive', bodyB, bodyA, pair);
}
matter.Events.trigger(bodyA, 'onCollideActive', { pair: pair });
matter.Events.trigger(bodyB, 'onCollideActive', { pair: pair });
@ -76,6 +96,16 @@ var MatterCollisionEvents = {
var bodyA = pair.bodyA;
var bodyB = pair.bodyB;
if (bodyA.gameObject)
{
bodyA.gameObject.emit('collideEnd', bodyA, bodyB, pair);
}
if (bodyB.gameObject)
{
bodyB.gameObject.emit('collideEnd', bodyB, bodyA, pair);
}
matter.Events.trigger(bodyA, 'onCollideEnd', { pair: pair });
matter.Events.trigger(bodyB, 'onCollideEnd', { pair: pair });