0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-27 09:50:52 -05:00

moved collision events into Engine.update, changed collisionStart to trigger before collisions resolved

This commit is contained in:
liabru 2014-07-09 17:46:44 +01:00
parent c5212e1ba4
commit 69b1d05efc

View file

@ -154,9 +154,6 @@ var Engine = {};
// update
Engine.update(engine, delta, correction);
// trigger events that may have occured during the step
_triggerCollisionEvents(engine);
// render
Engine.render(engine);
@ -165,7 +162,9 @@ var Engine = {};
};
/**
* Moves the simulation forward in time by `delta` ms. Triggers `beforeUpdate` and `afterUpdate` events.
* Moves the simulation forward in time by `delta` ms.
* Triggers `beforeUpdate` and `afterUpdate` events.
* Triggers `collisionStart`, `collisionActive` and `collisionEnd` events.
* @method update
* @param {engine} engine
* @param {number} delta
@ -243,6 +242,10 @@ var Engine = {};
if (engine.enableSleeping)
Sleeping.afterCollisions(pairs.list, timing.timeScale);
// trigger collision events
if (pairs.collisionStart.length > 0)
Events.trigger(engine, 'collisionStart', { pairs: pairs.collisionStart });
// iteratively resolve velocity between collisions
Resolver.preSolveVelocity(pairs.list);
for (i = 0; i < engine.velocityIterations; i++) {
@ -255,6 +258,13 @@ var Engine = {};
}
Resolver.postSolvePosition(allBodies);
// trigger collision events
if (pairs.collisionActive.length > 0)
Events.trigger(engine, 'collisionActive', { pairs: pairs.collisionActive });
if (pairs.collisionEnd.length > 0)
Events.trigger(engine, 'collisionEnd', { pairs: pairs.collisionEnd });
// update metrics log
Metrics.update(engine.metrics, engine);
@ -329,34 +339,6 @@ var Engine = {};
}
};
/**
* Triggers collision events
* @method _triggerMouseEvents
* @private
* @param {engine} engine
*/
var _triggerCollisionEvents = function(engine) {
var pairs = engine.pairs;
if (pairs.collisionStart.length > 0) {
Events.trigger(engine, 'collisionStart', {
pairs: pairs.collisionStart
});
}
if (pairs.collisionActive.length > 0) {
Events.trigger(engine, 'collisionActive', {
pairs: pairs.collisionActive
});
}
if (pairs.collisionEnd.length > 0) {
Events.trigger(engine, 'collisionEnd', {
pairs: pairs.collisionEnd
});
}
};
/*
*
* Events Documentation