UNPKG

complex-engine

Version:

JS Component Entity Framework for Gamedevelopment

155 lines (124 loc) 3.58 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: Engine.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: Engine.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>import Scene from './Scene'; import SimpleScene from './SimpleScene'; /** * Complex Engine. This class handles the rendering of the current scene. */ class Engine { constructor() { /** @var {Scene | null} */ this.scene = null; /** @var {Engine | null} */ this.instance = null; } /** * Gets current instance * @returns {Engine} */ static getInstance() { if (!Engine.instance) { Engine.instance = new Engine(); } return Engine.instance; } /** * Compose a simple scene for a very quick start * @param {function} setupFunction * @return {Engine} */ simpleScene(setupFunction) { const scene = new SimpleScene(); setupFunction.bind(scene)(); this.useScene(scene); return this; } /** * load a scene to be rendered * @param {Scene} scene * @deprecated * @return {this} */ loadScene(scene) { this.scene = scene; this.scene.load(); this.scene.run(); return this; } /** * Use a scene * @param scene * @return {Engine} */ useScene(scene) { this.scene = scene; this.scene.prepare(); return this; } /** * Start the rendering loop. This updates automatically with requestAnimationFrame * @return {Engine} */ start() { this._render(); return this; } /** * Render the scene and world. Updates with requestAnimationFrame * @private */ _render() { this.update(); requestAnimationFrame(() => { this._render(); }); } /** * render the loaded scene * @return {Engine} */ update() { if (this.scene) { this.scene.update(); } return this; } /** * @returns {Scene | null} */ getScene() { return this.scene; } } export default Engine; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Component.html">Component</a></li><li><a href="Engine.html">Engine</a></li><li><a href="Entity.html">Entity</a></li><li><a href="EntitySystem.html">EntitySystem</a></li><li><a href="GroupManager.html">GroupManager</a></li><li><a href="Manager.html">Manager</a></li><li><a href="Scene.html">Scene</a></li><li><a href="System.html">System</a></li><li><a href="VoidSystem.html">VoidSystem</a></li><li><a href="World.html">World</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sun Sep 08 2019 20:40:30 GMT+0200 (Central European Summer Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>