Colliders can now be toggled from active to inactive.

Collider.destroy added (but needs doing in World too).
This commit is contained in:
Richard Davey 2017-11-09 17:10:33 +00:00
parent b062e204dc
commit f165acfe5f
2 changed files with 27 additions and 1 deletions

View file

@ -10,6 +10,8 @@ var Collider = new Class({
{
this.world = world;
this.active = true;
this.overlapOnly = overlapOnly;
this.object1 = object1;
@ -30,6 +32,20 @@ var Collider = new Class({
this.callbackContext,
this.overlapOnly
);
},
destroy: function ()
{
this.world.removeCollider(this);
this.world = null;
this.object1 = null;
this.object2 = null;
this.collideCallback = null;
this.processCallback = null;
this.callbackContext = null;
}
});

View file

@ -249,6 +249,11 @@ var World = new Class({
return collider;
},
removeCollider: function (collider)
{
// TODO
},
update: function (time, delta)
{
if (this.isPaused || this.bodies.size === 0)
@ -286,7 +291,12 @@ var World = new Class({
for (i = 0; i < this.colliders.length; i++)
{
this.colliders[i].update();
var collider = this.colliders[i];
if (collider.active)
{
collider.update();
}
}
},