0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-31 18:14:55 -05:00

Trigger event on body itself before/after it's removed

Events.on(body, "beforeRemoved", callback);
Events.on(body, "afterRemoved", callback);
This commit is contained in:
Wtm 2016-06-05 13:42:05 +08:00
parent 49b665cfc4
commit ff281e0f61
4 changed files with 22 additions and 0 deletions

BIN
src/body/.Body.js.swp Normal file

Binary file not shown.

BIN
src/body/.Composite.js.swp Normal file

Binary file not shown.

View file

@ -634,6 +634,26 @@ var Axes = require('../geometry/Axes');
* *
*/ */
/**
* Fired before a body is going to be removed
*
* @event beforeRemoved
* @this {body} The body that is going to be removed
* @param {} event An event object
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/**
* Fired after a body was removed
*
* @event afterRemoved
* @this {body} The body that was removed
* @param {} event An event object
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/** /**
* Fired when a body starts sleeping (where `this` is the body). * Fired when a body starts sleeping (where `this` is the body).
* *

View file

@ -238,6 +238,7 @@ var Body = require('./Body');
* @return {composite} The original composite with the body removed * @return {composite} The original composite with the body removed
*/ */
Composite.removeBody = function(composite, body, deep) { Composite.removeBody = function(composite, body, deep) {
Events.trigger(body, 'beforeRemoved', {});
var position = Common.indexOf(composite.bodies, body); var position = Common.indexOf(composite.bodies, body);
if (position !== -1) { if (position !== -1) {
Composite.removeBodyAt(composite, position); Composite.removeBodyAt(composite, position);
@ -250,6 +251,7 @@ var Body = require('./Body');
} }
} }
Events.trigger(body, 'afterRemoved', {});
return composite; return composite;
}; };