From 2af54d51cdd4e9676e6a4e6bab8d0b940037eebd Mon Sep 17 00:00:00 2001 From: liabru Date: Sun, 26 Mar 2023 23:46:38 +0100 Subject: [PATCH] added event.timestamp and event.delta to collision events, closes #368 --- src/core/Engine.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/core/Engine.js b/src/core/Engine.js index e6bcf36..91b55ac 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -149,8 +149,13 @@ var Body = require('../body/Body'); Sleeping.afterCollisions(pairs.list); // trigger collision events - if (pairs.collisionStart.length > 0) - Events.trigger(engine, 'collisionStart', { pairs: pairs.collisionStart }); + if (pairs.collisionStart.length > 0) { + Events.trigger(engine, 'collisionStart', { + pairs: pairs.collisionStart, + timestamp: timing.timestamp, + delta: delta + }); + } // iteratively resolve position between collisions var positionDamping = Common.clamp(20 / engine.positionIterations, 0, 1); @@ -178,11 +183,21 @@ var Body = require('../body/Body'); Engine._bodiesUpdateVelocities(allBodies); // trigger collision events - if (pairs.collisionActive.length > 0) - Events.trigger(engine, 'collisionActive', { pairs: pairs.collisionActive }); + if (pairs.collisionActive.length > 0) { + Events.trigger(engine, 'collisionActive', { + pairs: pairs.collisionActive, + timestamp: timing.timestamp, + delta: delta + }); + } - if (pairs.collisionEnd.length > 0) - Events.trigger(engine, 'collisionEnd', { pairs: pairs.collisionEnd }); + if (pairs.collisionEnd.length > 0) { + Events.trigger(engine, 'collisionEnd', { + pairs: pairs.collisionEnd, + timestamp: timing.timestamp, + delta: delta + }); + } // clear force buffers Engine._bodiesClearForces(allBodies);