mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
moved event documentation to end of file for clarity
This commit is contained in:
parent
5830311daa
commit
8f53178715
1 changed files with 139 additions and 122 deletions
|
@ -5,9 +5,7 @@
|
||||||
* @class Engine
|
* @class Engine
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: multiple event handlers, before & after handlers
|
|
||||||
// TODO: viewports
|
// TODO: viewports
|
||||||
// TODO: frameskipping
|
|
||||||
|
|
||||||
var Engine = {};
|
var Engine = {};
|
||||||
|
|
||||||
|
@ -109,15 +107,6 @@ var Engine = {};
|
||||||
timestamp: timestamp
|
timestamp: timestamp
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired at the start of a tick, before any updates to the engine or timing
|
|
||||||
*
|
|
||||||
* @event beforeTick
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
Events.trigger(engine, 'beforeTick', event);
|
Events.trigger(engine, 'beforeTick', event);
|
||||||
|
|
||||||
delta = (timestamp - timing.timestamp) || _delta;
|
delta = (timestamp - timing.timestamp) || _delta;
|
||||||
|
@ -152,24 +141,6 @@ var Engine = {};
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired after engine timing updated, but just before engine state updated
|
|
||||||
*
|
|
||||||
* @event tick
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Fired just before an update
|
|
||||||
*
|
|
||||||
* @event beforeUpdate
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
Events.trigger(engine, 'tick beforeUpdate', event);
|
Events.trigger(engine, 'tick beforeUpdate', event);
|
||||||
|
|
||||||
// if world has been modified, clear the render scene graph
|
// if world has been modified, clear the render scene graph
|
||||||
|
@ -183,48 +154,12 @@ var Engine = {};
|
||||||
_triggerCollisionEvents(engine);
|
_triggerCollisionEvents(engine);
|
||||||
_triggerMouseEvents(engine);
|
_triggerMouseEvents(engine);
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired after engine update and all collision events
|
|
||||||
*
|
|
||||||
* @event afterUpdate
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Fired just before rendering
|
|
||||||
*
|
|
||||||
* @event beforeRender
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
Events.trigger(engine, 'afterUpdate beforeRender', event);
|
Events.trigger(engine, 'afterUpdate beforeRender', event);
|
||||||
|
|
||||||
// render
|
// render
|
||||||
if (engine.render.options.enabled)
|
if (engine.render.options.enabled)
|
||||||
engine.render.controller.world(engine);
|
engine.render.controller.world(engine);
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired after rendering
|
|
||||||
*
|
|
||||||
* @event afterRender
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Fired after engine update and after rendering
|
|
||||||
*
|
|
||||||
* @event afterTick
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
Events.trigger(engine, 'afterTick afterRender', event);
|
Events.trigger(engine, 'afterTick afterRender', event);
|
||||||
})();
|
})();
|
||||||
};
|
};
|
||||||
|
@ -373,45 +308,18 @@ var Engine = {};
|
||||||
var mouse = engine.input.mouse,
|
var mouse = engine.input.mouse,
|
||||||
mouseEvents = mouse.sourceEvents;
|
mouseEvents = mouse.sourceEvents;
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired when the mouse has moved (or a touch moves) during the last step
|
|
||||||
*
|
|
||||||
* @event mousemove
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {mouse} event.mouse The engine's mouse instance
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
if (mouseEvents.mousemove) {
|
if (mouseEvents.mousemove) {
|
||||||
Events.trigger(engine, 'mousemove', {
|
Events.trigger(engine, 'mousemove', {
|
||||||
mouse: mouse
|
mouse: mouse
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired when the mouse is down (or a touch has started) during the last step
|
|
||||||
*
|
|
||||||
* @event mousedown
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {mouse} event.mouse The engine's mouse instance
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
if (mouseEvents.mousedown) {
|
if (mouseEvents.mousedown) {
|
||||||
Events.trigger(engine, 'mousedown', {
|
Events.trigger(engine, 'mousedown', {
|
||||||
mouse: mouse
|
mouse: mouse
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired when the mouse is up (or a touch has ended) during the last step
|
|
||||||
*
|
|
||||||
* @event mouseup
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {mouse} event.mouse The engine's mouse instance
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
if (mouseEvents.mouseup) {
|
if (mouseEvents.mouseup) {
|
||||||
Events.trigger(engine, 'mouseup', {
|
Events.trigger(engine, 'mouseup', {
|
||||||
mouse: mouse
|
mouse: mouse
|
||||||
|
@ -431,48 +339,18 @@ var Engine = {};
|
||||||
var _triggerCollisionEvents = function(engine) {
|
var _triggerCollisionEvents = function(engine) {
|
||||||
var pairs = engine.pairs;
|
var pairs = engine.pairs;
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired after engine update, provides a list of all pairs that have started to collide in the current tick (if any)
|
|
||||||
*
|
|
||||||
* @event collisionStart
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {} event.pairs List of affected pairs
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
if (pairs.collisionStart.length > 0) {
|
if (pairs.collisionStart.length > 0) {
|
||||||
Events.trigger(engine, 'collisionStart', {
|
Events.trigger(engine, 'collisionStart', {
|
||||||
pairs: pairs.collisionStart
|
pairs: pairs.collisionStart
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired after engine update, provides a list of all pairs that are colliding in the current tick (if any)
|
|
||||||
*
|
|
||||||
* @event collisionActive
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {} event.pairs List of affected pairs
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
if (pairs.collisionActive.length > 0) {
|
if (pairs.collisionActive.length > 0) {
|
||||||
Events.trigger(engine, 'collisionActive', {
|
Events.trigger(engine, 'collisionActive', {
|
||||||
pairs: pairs.collisionActive
|
pairs: pairs.collisionActive
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired after engine update, provides a list of all pairs that have ended collision in the current tick (if any)
|
|
||||||
*
|
|
||||||
* @event collisionEnd
|
|
||||||
* @param {} event An event object
|
|
||||||
* @param {} event.pairs List of affected pairs
|
|
||||||
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
|
||||||
* @param {} event.source The source object of the event
|
|
||||||
* @param {} event.name The name of the event
|
|
||||||
*/
|
|
||||||
if (pairs.collisionEnd.length > 0) {
|
if (pairs.collisionEnd.length > 0) {
|
||||||
Events.trigger(engine, 'collisionEnd', {
|
Events.trigger(engine, 'collisionEnd', {
|
||||||
pairs: pairs.collisionEnd
|
pairs: pairs.collisionEnd
|
||||||
|
@ -480,4 +358,143 @@ var Engine = {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Events Documentation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired at the start of a tick, before any updates to the engine or timing
|
||||||
|
*
|
||||||
|
* @event beforeTick
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired after engine timing updated, but just before engine state updated
|
||||||
|
*
|
||||||
|
* @event tick
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired just before an update
|
||||||
|
*
|
||||||
|
* @event beforeUpdate
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired after engine update and all collision events
|
||||||
|
*
|
||||||
|
* @event afterUpdate
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired just before rendering
|
||||||
|
*
|
||||||
|
* @event beforeRender
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired after rendering
|
||||||
|
*
|
||||||
|
* @event afterRender
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired after engine update and after rendering
|
||||||
|
*
|
||||||
|
* @event afterTick
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when the mouse has moved (or a touch moves) during the last step
|
||||||
|
*
|
||||||
|
* @event mousemove
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {mouse} event.mouse The engine's mouse instance
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when the mouse is down (or a touch has started) during the last step
|
||||||
|
*
|
||||||
|
* @event mousedown
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {mouse} event.mouse The engine's mouse instance
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when the mouse is up (or a touch has ended) during the last step
|
||||||
|
*
|
||||||
|
* @event mouseup
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {mouse} event.mouse The engine's mouse instance
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired after engine update, provides a list of all pairs that have started to collide in the current tick (if any)
|
||||||
|
*
|
||||||
|
* @event collisionStart
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {} event.pairs List of affected pairs
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired after engine update, provides a list of all pairs that are colliding in the current tick (if any)
|
||||||
|
*
|
||||||
|
* @event collisionActive
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {} event.pairs List of affected pairs
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired after engine update, provides a list of all pairs that have ended collision in the current tick (if any)
|
||||||
|
*
|
||||||
|
* @event collisionEnd
|
||||||
|
* @param {} event An event object
|
||||||
|
* @param {} event.pairs List of affected pairs
|
||||||
|
* @param {DOMHighResTimeStamp} event.timestamp The timestamp of the current tick
|
||||||
|
* @param {} event.source The source object of the event
|
||||||
|
* @param {} event.name The name of the event
|
||||||
|
*/
|
||||||
|
|
||||||
})();
|
})();
|
Loading…
Reference in a new issue