Added support for beforeUpdate and afterUpdate world events

This commit is contained in:
Richard Davey 2017-11-23 01:45:38 +00:00
parent b0f2b833c8
commit dbad873236
4 changed files with 52 additions and 0 deletions

View file

@ -68,6 +68,18 @@ var World = new Class({
{ {
var localEvents = this.events; var localEvents = this.events;
MatterEvents.on(this.engine, 'beforeUpdate', function (event) {
localEvents.dispatch(new PhysicsEvent.BEFORE_UPDATE(event));
});
MatterEvents.on(this.engine, 'afterUpdate', function (event) {
localEvents.dispatch(new PhysicsEvent.AFTER_UPDATE(event));
});
MatterEvents.on(this.engine, 'collisionStart', function (event) { MatterEvents.on(this.engine, 'collisionStart', function (event) {
localEvents.dispatch(new PhysicsEvent.COLLISION_START(event.pairs)); localEvents.dispatch(new PhysicsEvent.COLLISION_START(event.pairs));

View file

@ -0,0 +1,19 @@
var Class = require('../../../utils/Class');
var Event = require('../../../events/Event');
var AfterUpdateEvent = new Class({
Extends: Event,
initialize:
function AfterUpdateEvent (event)
{
Event.call(this, 'AFTER_UPDATE_EVENT');
this.event = event;
}
});
module.exports = AfterUpdateEvent;

View file

@ -0,0 +1,19 @@
var Class = require('../../../utils/Class');
var Event = require('../../../events/Event');
var BeforeUpdateEvent = new Class({
Extends: Event,
initialize:
function BeforeUpdateEvent (event)
{
Event.call(this, 'BEFORE_UPDATE_EVENT');
this.event = event;
}
});
module.exports = BeforeUpdateEvent;

View file

@ -2,6 +2,8 @@
module.exports = { module.exports = {
AFTER_UPDATE: require('./AfterUpdateEvent'),
BEFORE_UPDATE: require('./BeforeUpdateEvent'),
COLLISION_ACTIVE: require('./CollisionActiveEvent'), COLLISION_ACTIVE: require('./CollisionActiveEvent'),
COLLISION_END: require('./CollisionEndEvent'), COLLISION_END: require('./CollisionEndEvent'),
COLLISION_START: require('./CollisionStartEvent'), COLLISION_START: require('./CollisionStartEvent'),