0
0
Fork 0
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:
liabru 2014-04-24 16:36:36 +01:00
parent 5830311daa
commit 8f53178715

View file

@ -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,6 +339,131 @@ var Engine = {};
var _triggerCollisionEvents = function(engine) { var _triggerCollisionEvents = function(engine) {
var pairs = engine.pairs; 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 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) * Fired after engine update, provides a list of all pairs that have started to collide in the current tick (if any)
* *
@ -441,11 +474,6 @@ var Engine = {};
* @param {} event.source The source object of the event * @param {} event.source The source object of the event
* @param {} event.name The name of the event * @param {} event.name The name of the event
*/ */
if (pairs.collisionStart.length > 0) {
Events.trigger(engine, 'collisionStart', {
pairs: pairs.collisionStart
});
}
/** /**
* Fired after engine update, provides a list of all pairs that are colliding in the current tick (if any) * Fired after engine update, provides a list of all pairs that are colliding in the current tick (if any)
@ -457,11 +485,6 @@ var Engine = {};
* @param {} event.source The source object of the event * @param {} event.source The source object of the event
* @param {} event.name The name of the event * @param {} event.name The name of the event
*/ */
if (pairs.collisionActive.length > 0) {
Events.trigger(engine, 'collisionActive', {
pairs: pairs.collisionActive
});
}
/** /**
* Fired after engine update, provides a list of all pairs that have ended collision in the current tick (if any) * Fired after engine update, provides a list of all pairs that have ended collision in the current tick (if any)
@ -473,11 +496,5 @@ var Engine = {};
* @param {} event.source The source object of the event * @param {} event.source The source object of the event
* @param {} event.name The name of the event * @param {} event.name The name of the event
*/ */
if (pairs.collisionEnd.length > 0) {
Events.trigger(engine, 'collisionEnd', {
pairs: pairs.collisionEnd
});
}
};
})(); })();