0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-12 16:08:50 -05:00

added Engine.render, moved respective engine event triggers into Engine.update and Engine.render

This commit is contained in:
liabru 2014-05-02 12:23:13 +01:00
parent bc35c93106
commit d1f607edb8

View file

@ -81,7 +81,9 @@ var Engine = {};
};
/**
* Description
* A simple game loop utility, that calls `Engine.update` and `Engine.render` on the `requestAnimationFrame` event automatically.
* Handles time correction and non-fixed dynamic timing (if enabled).
* Triggers `beforeTick`, `tick` and `afterTick` events.
* @method run
* @param {engine} engine
*/
@ -152,7 +154,7 @@ var Engine = {};
frameCounter = 0;
}
Events.trigger(engine, 'tick beforeUpdate', event);
Events.trigger(engine, 'tick', event);
// if world has been modified, clear the render scene graph
if (engine.world.isModified)
@ -165,18 +167,15 @@ var Engine = {};
_triggerCollisionEvents(engine);
_triggerMouseEvents(engine);
Events.trigger(engine, 'afterUpdate beforeRender', event);
// render
if (engine.render.options.enabled)
engine.render.controller.world(engine);
Engine.render(engine);
Events.trigger(engine, 'afterTick afterRender', event);
Events.trigger(engine, 'afterTick', event);
})();
};
/**
* Description
* Moves the simulation forward in time by `delta`. Triggers `beforeUpdate` and `afterUpdate` events.
* @method update
* @param {engine} engine
* @param {number} delta
@ -190,6 +189,13 @@ var Engine = {};
broadphasePairs = [],
i;
// create an event object
var event = {
timestamp: engine.timing.timestamp
};
Events.trigger(engine, 'beforeUpdate', event);
// get lists of all bodies and constraints, no matter what composites they are in
var allBodies = Composite.allBodies(world),
allConstraints = Composite.allConstraints(world);
@ -264,8 +270,27 @@ var Engine = {};
if (world.isModified)
Composite.setModified(world, false, false, true);
Events.trigger(engine, 'afterUpdate', event);
return engine;
};
/**
* Renders the world by calling its defined renderer `engine.render.controller`. Triggers `beforeRender` and `afterRender` events.
* @method render
* @param {engine} engineA
* @param {engine} engineB
*/
Engine.render = function(engine) {
// create an event object
var event = {
timestamp: engine.timing.timestamp
};
Events.trigger(engine, 'beforeRender', event);
engine.render.controller.world(engine);
Events.trigger(engine, 'afterRender', event);
};
/**
* Description