/** * @author Mat Groves http://matgroves.com/ @Doormat23 */ /** * A Stage represents the root of the display tree. Everything connected to the stage is rendered * * @class Stage * @extends DisplayObjectContainer * @constructor * @param backgroundColor {Number} the background color of the stage, easiest way to pass this in is in hex format * like: 0xFFFFFF for white */ PIXI.Stage = function(backgroundColor) { PIXI.DisplayObjectContainer.call( this ); /** * [read-only] Current transform of the object based on world (parent) factors * * @property worldTransform * @type Mat3 * @readOnly * @private */ this.worldTransform = PIXI.mat3.create(); /** * Whether or not the stage is interactive * * @property interactive * @type Boolean */ this.interactive = true; /** * The interaction manage for this stage, manages all interactive activity on the stage * * @property interactive * @type InteractionManager */ this.interactionManager = new PIXI.InteractionManager(this); /** * Whether the stage is dirty and needs to have interactions updated * * @property dirty * @type Boolean * @private */ this.dirty = true; this.__childrenAdded = []; this.__childrenRemoved = []; //the stage is it's own stage this.stage = this; //optimize hit detection a bit this.stage.hitArea = new PIXI.Rectangle(0,0,100000, 100000); this.setBackgroundColor(backgroundColor); this.worldVisible = true; } // constructor PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); PIXI.Stage.prototype.constructor = PIXI.Stage; /** * Sets another DOM element which can receive mouse/touch interactions instead of the default Canvas element. * This is useful for when you have other DOM elements ontop of the Canvas element. * * @method setInteractionDelegate * @param domElement {DOMElement} This new domElement which will receive mouse/touch events */ PIXI.Stage.prototype.setInteractionDelegate = function(domElement) { this.interactionManager.setTargetDomElement( domElement ); } /* * Updates the object transform for rendering * * @method updateTransform * @private */ PIXI.Stage.prototype.updateTransform = function() { this.worldAlpha = 1; this.vcount = PIXI.visibleCount; for(var i=0,j=this.children.length; i<j; i++) { this.children[i].updateTransform(); } if(this.dirty) { this.dirty = false; // update interactive! this.interactionManager.dirty = true; } if(this.interactive)this.interactionManager.update(); } /** * Sets the background color for the stage * * @method setBackgroundColor * @param backgroundColor {Number} the color of the background, easiest way to pass this in is in hex format * like: 0xFFFFFF for white */ PIXI.Stage.prototype.setBackgroundColor = function(backgroundColor) { this.backgroundColor = backgroundColor || 0x000000; this.backgroundColorSplit = hex2rgb(this.backgroundColor); var hex = this.backgroundColor.toString(16); hex = "000000".substr(0, 6 - hex.length) + hex; this.backgroundColorString = "#" + hex; } /** * This will return the point containing global coords of the mouse. * * @method getMousePosition * @return {Point} The point containing the coords of the global InteractionData position. */ PIXI.Stage.prototype.getMousePosition = function() { return this.interactionManager.mouse.global; }