Skip to content

Commit

Permalink
fix Demo.reset to fully reset ids
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Dec 25, 2015
1 parent 19656cd commit 500d566
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 5 additions & 1 deletion demo/js/Demo.js
Expand Up @@ -24,7 +24,8 @@
}

// Matter aliases
var Example = Matter.Example,
var Body = Matter.Body,
Example = Matter.Example,
Engine = Matter.Engine,
World = Matter.World,
Common = Matter.Common,
Expand Down Expand Up @@ -295,6 +296,9 @@
demo.sceneEvents = [];

// reset id pool
Body._nextCollidingGroupId = 1;
Body._nextNonCollidingGroupId = -1;
Body._nextCategory = 0x0001;
Common._nextId = 0;

// reset random seed
Expand Down
15 changes: 7 additions & 8 deletions src/body/Body.js
Expand Up @@ -24,10 +24,9 @@ var Axes = require('../geometry/Axes');
(function() {

Body._inertiaScale = 4;

var _nextCollidingGroupId = 1,
_nextNonCollidingGroupId = -1,
_nextCategory = 0x0001;
Body._nextCollidingGroupId = 1;
Body._nextNonCollidingGroupId = -1;
Body._nextCategory = 0x0001;

/**
* Creates a new rigid body model. The options parameter is an object that specifies any properties you wish to override the defaults.
Expand Down Expand Up @@ -100,9 +99,9 @@ var Axes = require('../geometry/Axes');
*/
Body.nextGroup = function(isNonColliding) {
if (isNonColliding)
return _nextNonCollidingGroupId--;
return Body._nextNonCollidingGroupId--;

return _nextCollidingGroupId++;
return Body._nextCollidingGroupId++;
};

/**
Expand All @@ -112,8 +111,8 @@ var Axes = require('../geometry/Axes');
* @return {Number} Unique category bitfield
*/
Body.nextCategory = function() {
_nextCategory = _nextCategory << 1;
return _nextCategory;
Body._nextCategory = Body._nextCategory << 1;
return Body._nextCategory;
};

/**
Expand Down

0 comments on commit 500d566

Please sign in to comment.