From 6516c5be8d897f3ffd34b8357357292357150206 Mon Sep 17 00:00:00 2001 From: liabru Date: Mon, 10 Mar 2014 21:25:07 +0000 Subject: [PATCH] moved collision event triggers --- src/core/Engine.js | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/core/Engine.js b/src/core/Engine.js index 5a308a4..7e1567b 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -142,10 +142,32 @@ var Engine = {}; Events.trigger(engine, 'tick beforeUpdate', event); + // update 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); + // render if (engine.render.options.enabled) engine.render.controller.world(engine); @@ -175,7 +197,7 @@ var Engine = {}; Body.applyGravityAll(world.bodies, world.gravity); MouseConstraint.update(engine.mouseConstraint, world.bodies, engine.input); - + Body.updateAll(world.bodies, delta * engine.timeScale, correction, world.bounds); // update all constraints @@ -199,23 +221,6 @@ var Engine = {}; Manager.updatePairs(pairs, collisions); 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 if (engine.enableSleeping) Sleeping.afterCollisions(pairs.list);