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:
parent
c5212e1ba4
commit
69b1d05efc
1 changed files with 14 additions and 32 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue