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:
parent
bc35c93106
commit
d1f607edb8
1 changed files with 33 additions and 8 deletions
|
@ -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
|
* @method run
|
||||||
* @param {engine} engine
|
* @param {engine} engine
|
||||||
*/
|
*/
|
||||||
|
@ -152,7 +154,7 @@ var Engine = {};
|
||||||
frameCounter = 0;
|
frameCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Events.trigger(engine, 'tick beforeUpdate', event);
|
Events.trigger(engine, 'tick', event);
|
||||||
|
|
||||||
// if world has been modified, clear the render scene graph
|
// if world has been modified, clear the render scene graph
|
||||||
if (engine.world.isModified)
|
if (engine.world.isModified)
|
||||||
|
@ -165,18 +167,15 @@ var Engine = {};
|
||||||
_triggerCollisionEvents(engine);
|
_triggerCollisionEvents(engine);
|
||||||
_triggerMouseEvents(engine);
|
_triggerMouseEvents(engine);
|
||||||
|
|
||||||
Events.trigger(engine, 'afterUpdate beforeRender', event);
|
|
||||||
|
|
||||||
// render
|
// render
|
||||||
if (engine.render.options.enabled)
|
Engine.render(engine);
|
||||||
engine.render.controller.world(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
|
* @method update
|
||||||
* @param {engine} engine
|
* @param {engine} engine
|
||||||
* @param {number} delta
|
* @param {number} delta
|
||||||
|
@ -190,6 +189,13 @@ var Engine = {};
|
||||||
broadphasePairs = [],
|
broadphasePairs = [],
|
||||||
i;
|
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
|
// get lists of all bodies and constraints, no matter what composites they are in
|
||||||
var allBodies = Composite.allBodies(world),
|
var allBodies = Composite.allBodies(world),
|
||||||
allConstraints = Composite.allConstraints(world);
|
allConstraints = Composite.allConstraints(world);
|
||||||
|
@ -264,8 +270,27 @@ var Engine = {};
|
||||||
if (world.isModified)
|
if (world.isModified)
|
||||||
Composite.setModified(world, false, false, true);
|
Composite.setModified(world, false, false, true);
|
||||||
|
|
||||||
|
Events.trigger(engine, 'afterUpdate', event);
|
||||||
|
|
||||||
return engine;
|
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
|
* Description
|
||||||
|
|
Loading…
Reference in a new issue