From 964898bea24b234e41e1f22d52f6c4d0601e03e9 Mon Sep 17 00:00:00 2001 From: liabru Date: Tue, 29 Apr 2014 17:34:45 +0100 Subject: [PATCH] added Composite.rebase --- src/body/Composite.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/body/Composite.js b/src/body/Composite.js index 31f8001..3ccb0bc 100644 --- a/src/body/Composite.js +++ b/src/body/Composite.js @@ -396,4 +396,24 @@ var Composite = {}; return compositeA; }; + /** + * Assigns new ids for all objects in the composite, recursively + * @method rebase + * @param {composite} composite + * @return {composite} Returns composite + */ + Composite.rebase = function(composite) { + var objects = Composite.allBodies(composite) + .concat(Composite.allConstraints(composite)) + .concat(Composite.allComposites(composite)); + + for (var i = 0; i < objects.length; i++) { + objects[i].id = Common.nextId(); + } + + Composite.setModified(composite, true, true, false); + + return composite; + }; + })(); \ No newline at end of file