123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>JSDoc: Source: Object2D.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: Object2D.js</h1>
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>"use strict";
- import {Vector2} from "./math/Vector2.js";
- import {Matrix} from "./math/Matrix.js";
- import {UUID} from "./math/UUID.js";
- /**
- * Base 2D object class, implements all the object positioning and scalling features.
- *
- * @class
- */
- function Object2D()
- {
- /**
- * UUID of the object.
- */
- this.uuid = UUID.generate();
- /**
- * List of children objects attached to the object.
- */
- this.children = [];
- /**
- * Parent object, the object position is affected by its parent position.
- */
- this.parent = null;
- /**
- * Position of the object.
- */
- this.position = new Vector2(0, 0);
- /**
- * Scale of the object.
- */
- this.scale = new Vector2(1, 1);
- /**
- * Rotation of the object relative to its center.
- */
- this.rotation = 0.0;
- /**
- * Indicates if the object is visible.
- */
- this.visible = true;
- /**
- * Layer of this object, objects are sorted by layer value.
- *
- * Lower layer value is draw first.
- */
- this.layer = 0;
- /**
- * Local transformation matrix applied to the object.
- */
- this.matrix = new Matrix();
- /**
- * Global transformation matrix multiplied by the parent matrix.
- *
- * Used to transform the object before projecting into screen coordinates.
- */
- this.globalMatrix = new Matrix();
- /**
- * Inverse of the global matrix.
- *
- * Used to convert pointer input points into object coordinates.
- */
- this.inverseGlobalMatrix = new Matrix();
- /**
- * If true the matrix is updated before rendering the object.
- */
- this.matrixNeedsUpdate = true;
- /**
- * Indicates if its possible to drag the object around.
- *
- * If true the onPointerDrag callback is used to update the state of the object.
- */
- this.draggable = true;
- /**
- * Flag indicating if the pointer is inside of the element.
- *
- * Used to control object event.
- */
- this.pointerInside = false;
- /**
- * Flag to indicate if the object is currently being dragged.
- */
- this.beingDragged = false;
- }
- /**
- * Traverse the object tree and run a function for all objects.
- *
- * @param callback Callback function that receives the object as parameter.
- */
- Object2D.prototype.traverse = function(callback)
- {
- callback(this);
- var children = this.children;
- for(var i = 0; i < children.length; i++)
- {
- children[i].traverse(callback);
- }
- };
- /**
- * Attach a children to the object.
- *
- * @param object Object to attach to this object.
- */
- Object2D.prototype.add = function(object)
- {
- object.parent = this;
- this.children.push(object);
- };
- /**
- * Remove object from the children list.
- *
- * @param object Object to be removed.
- */
- Object2D.prototype.remove = function(object)
- {
- var index = this.children.indexOf(object);
- if(index !== -1)
- {
- this.children[index].parent = null;
- this.children.splice(index, 1)
- }
- };
- /**
- * Check if a point is inside of the object.
- */
- Object2D.prototype.isInside = function(point)
- {
- return false;
- };
- /**
- * Update the transformation matrix of the object.
- */
- Object2D.prototype.updateMatrix = function(context)
- {
- if(this.matrixNeedsUpdate)
- {
- this.matrix.compose(this.position.x, this.position.y, this.scale.x, this.scale.y, this.rotation);
- this.globalMatrix.copy(this.matrix);
- if(this.parent !== null)
- {
- this.globalMatrix.premultiply(this.parent.globalMatrix);
- }
- this.inverseGlobalMatrix = this.globalMatrix.getInverse()
- //this.matrixNeedsUpdate = false;
- }
- };
- /**
- * Draw the object into the canvas.
- *
- * Has to be implemented by underlying classes.
- *
- * @param context Canvas 2d drawing context.
- */
- Object2D.prototype.draw = function(context){};
- /**
- * Callback method called every time before the object is draw into the canvas.
- *
- * Can be used to run preparation code, move the object, etc.
- */
- Object2D.prototype.onUpdate = null;
- /**
- * Callback method called when the pointer enters the object.
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onPointerEnter = null;
- /**
- * Callback method called when the was inside of the object and leaves the object.
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onPointerLeave = null;
- /**
- * Callback method while the pointer is over (inside) of the object.
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onPointerOver = null;
- /**
- * Callback method while the object is being dragged across the screen.
- *
- * Receives (pointer, viewport, delta) as arguments. Delta is the movement of the pointer already translated into local object coordinates.
- */
- Object2D.prototype.onPointerDrag = null;
- /**
- * Callback method called while the pointer button is pressed.
- *
- * Receives (pointer, viewport) as arguments.
- */
- Object2D.prototype.onButtonPressed = null;
- /**
- * Callback method called when the pointer button is pressed down (single time).
- */
- Object2D.prototype.onButtonDown = null;
- /**
- * Callback method called when the pointer button is released (single time).
- */
- Object2D.prototype.onButtonUp = null;
- export {Object2D};
- </code></pre>
- </article>
- </section>
- </div>
- <nav>
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="EventManager.html">EventManager</a></li><li><a href="Object2D.html">Object2D</a></li><li><a href="Renderer.html">Renderer</a></li><li><a href="Viewport.html">Viewport</a></li></ul>
- </nav>
- <br class="clear">
- <footer>
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.2</a> on Mon Jun 03 2019 12:31:58 GMT+0100 (Western European Summer Time)
- </footer>
- <script> prettyPrint(); </script>
- <script src="scripts/linenumber.js"> </script>
- </body>
- </html>
|