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

added event.timestamp and event.delta to collision events, closes #368

This commit is contained in:
liabru 2023-03-26 23:46:38 +01:00
parent 96557859f9
commit 2af54d51cd

View file

@ -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);