mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
moved collision event triggers
This commit is contained in:
parent
6f5e0d0036
commit
6516c5be8d
1 changed files with 23 additions and 18 deletions
|
@ -142,10 +142,32 @@ var Engine = {};
|
||||||
|
|
||||||
Events.trigger(engine, 'tick beforeUpdate', event);
|
Events.trigger(engine, 'tick beforeUpdate', event);
|
||||||
|
|
||||||
|
// update
|
||||||
Engine.update(engine, delta, correction);
|
Engine.update(engine, delta, correction);
|
||||||
|
|
||||||
|
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.trigger(engine, 'afterUpdate beforeRender', event);
|
Events.trigger(engine, 'afterUpdate beforeRender', event);
|
||||||
|
|
||||||
|
// render
|
||||||
if (engine.render.options.enabled)
|
if (engine.render.options.enabled)
|
||||||
engine.render.controller.world(engine);
|
engine.render.controller.world(engine);
|
||||||
|
|
||||||
|
@ -175,7 +197,7 @@ var Engine = {};
|
||||||
Body.applyGravityAll(world.bodies, world.gravity);
|
Body.applyGravityAll(world.bodies, world.gravity);
|
||||||
|
|
||||||
MouseConstraint.update(engine.mouseConstraint, world.bodies, engine.input);
|
MouseConstraint.update(engine.mouseConstraint, world.bodies, engine.input);
|
||||||
|
|
||||||
Body.updateAll(world.bodies, delta * engine.timeScale, correction, world.bounds);
|
Body.updateAll(world.bodies, delta * engine.timeScale, correction, world.bounds);
|
||||||
|
|
||||||
// update all constraints
|
// update all constraints
|
||||||
|
@ -199,23 +221,6 @@ var Engine = {};
|
||||||
Manager.updatePairs(pairs, collisions);
|
Manager.updatePairs(pairs, collisions);
|
||||||
Manager.removeOldPairs(pairs);
|
Manager.removeOldPairs(pairs);
|
||||||
|
|
||||||
// trigger collision events
|
|
||||||
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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// wake up bodies involved in collisions
|
// wake up bodies involved in collisions
|
||||||
if (engine.enableSleeping)
|
if (engine.enableSleeping)
|
||||||
Sleeping.afterCollisions(pairs.list);
|
Sleeping.afterCollisions(pairs.list);
|
||||||
|
|
Loading…
Reference in a new issue