mirror of
https://github.com/liabru/matter-js.git
synced 2025-03-14 00:38:41 -04:00
Merge ff281e0f61
into acb99b6f87
This commit is contained in:
commit
0c30ee9fa2
4 changed files with 37 additions and 0 deletions
BIN
src/body/.Body.js.swp
Normal file
BIN
src/body/.Body.js.swp
Normal file
Binary file not shown.
BIN
src/body/.Composite.js.swp
Normal file
BIN
src/body/.Composite.js.swp
Normal file
Binary file not shown.
|
@ -877,6 +877,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).
|
||||
*
|
||||
|
|
|
@ -175,6 +175,11 @@ var Body = require('./Body');
|
|||
* @return {composite} The original compositeA with the objects from compositeB added
|
||||
*/
|
||||
Composite.addComposite = function(compositeA, compositeB) {
|
||||
if (compositeA.composites.find(function (compos) {
|
||||
return compos.id == compositeB.id;
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
compositeA.composites.push(compositeB);
|
||||
compositeB.parent = compositeA;
|
||||
Composite.setModified(compositeA, true, true, false);
|
||||
|
@ -235,6 +240,11 @@ var Body = require('./Body');
|
|||
* @return {composite} The original composite with the body added
|
||||
*/
|
||||
Composite.addBody = function(composite, body) {
|
||||
if (composite.bodies.find(function (bodyB) {
|
||||
return bodyB.id == body.id;
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
composite.bodies.push(body);
|
||||
Composite.setModified(composite, true, true, false);
|
||||
return composite;
|
||||
|
@ -250,6 +260,7 @@ var Body = require('./Body');
|
|||
* @return {composite} The original composite with the body removed
|
||||
*/
|
||||
Composite.removeBody = function(composite, body, deep) {
|
||||
Events.trigger(body, 'beforeRemoved', {});
|
||||
var position = Common.indexOf(composite.bodies, body);
|
||||
|
||||
if (position !== -1) {
|
||||
|
@ -263,6 +274,7 @@ var Body = require('./Body');
|
|||
}
|
||||
}
|
||||
|
||||
Events.trigger(body, 'afterRemoved', {});
|
||||
return composite;
|
||||
};
|
||||
|
||||
|
@ -289,6 +301,11 @@ var Body = require('./Body');
|
|||
* @return {composite} The original composite with the constraint added
|
||||
*/
|
||||
Composite.addConstraint = function(composite, constraint) {
|
||||
if (composite.constraints.find(function (constraintB) {
|
||||
return constraintB.id == constraint.id;
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
composite.constraints.push(constraint);
|
||||
Composite.setModified(composite, true, true, false);
|
||||
return composite;
|
||||
|
|
Loading…
Add table
Reference in a new issue