0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-27 09:50:52 -05:00

added composite events

This commit is contained in:
liabru 2014-07-12 17:34:54 +01:00
parent 8aa148d2ec
commit 2841522f3b

View file

@ -63,6 +63,7 @@ var Composite = {};
/**
* Generic add function. Adds one or many body(s), constraint(s) or a composite(s) to the given composite.
* Triggers `beforeAdd` and `afterAdd` events on the `composite`.
* @method add
* @param {composite} composite
* @param {} object
@ -71,6 +72,8 @@ var Composite = {};
Composite.add = function(composite, object) {
var objects = [].concat(object);
Events.trigger(composite, 'beforeAdd', { object: object });
for (var i = 0; i < objects.length; i++) {
var obj = objects[i];
@ -92,12 +95,15 @@ var Composite = {};
}
}
Events.trigger(composite, 'afterAdd', { object: object });
return composite;
};
/**
* Generic remove function. Removes one or many body(s), constraint(s) or a composite(s) to the given composite.
* Optionally searching its children recursively.
* Triggers `beforeRemove` and `afterRemove` events on the `composite`.
* @method remove
* @param {composite} composite
* @param {} object
@ -107,6 +113,8 @@ var Composite = {};
Composite.remove = function(composite, object, deep) {
var objects = [].concat(object);
Events.trigger(composite, 'beforeRemove', { object: object });
for (var i = 0; i < objects.length; i++) {
var obj = objects[i];
@ -128,6 +136,8 @@ var Composite = {};
}
}
Events.trigger(composite, 'afterRemove', { object: object });
return composite;
};
@ -431,6 +441,52 @@ var Composite = {};
return composite;
};
/*
*
* Events Documentation
*
*/
/**
* Fired when a call to `Composite.add` is made, before objects have been added.
*
* @event beforeAdd
* @param {} event An event object
* @param {} event.object The object(s) to be added (may be a single body, constraint, composite or a mixed array of these)
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/**
* Fired when a call to `Composite.add` is made, after objects have been added.
*
* @event afterAdd
* @param {} event An event object
* @param {} event.object The object(s) that have been added (may be a single body, constraint, composite or a mixed array of these)
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/**
* Fired when a call to `Composite.remove` is made, before objects have been removed.
*
* @event beforeRemove
* @param {} event An event object
* @param {} event.object The object(s) to be removed (may be a single body, constraint, composite or a mixed array of these)
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/**
* Fired when a call to `Composite.remove` is made, after objects have been removed.
*
* @event afterRemove
* @param {} event An event object
* @param {} event.object The object(s) that have been removed (may be a single body, constraint, composite or a mixed array of these)
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/*
*
* Properties Documentation