fix: release collisions on leaving room

This commit is contained in:
cha0s 2019-05-26 12:28:41 -05:00
parent 0f61faabb4
commit b336a33727

View File

@ -36,11 +36,7 @@ export class Collider extends decorate(Trait) {
}
destroy() {
for (let i = 0; i < this._isCollidingWith.length; i++) {
const entity = this._isCollidingWith[i];
entity.emit('collisionEnd', this.entity);
}
this._isCollidingWith = [];
this.entity.releaseAllCollisions();
}
get collisionGroup() {
@ -76,6 +72,10 @@ export class Collider extends decorate(Trait) {
}
},
removedFromRoom: () => {
this.entity.releaseAllCollisions();
},
};
}
@ -87,6 +87,14 @@ export class Collider extends decorate(Trait) {
return -1 !== this._collidesWithGroups.indexOf(collisionGroup);
},
releaseAllCollisions: () => {
for (let i = 0; i < this._isCollidingWith.length; i++) {
const entity = this._isCollidingWith[i];
entity.emit('collisionEnd', this.entity);
}
this._isCollidingWith = [];
},
};
}
}