PIXI.DisplayObjectContainer = function (){ PIXI.DisplayObject.call(this); this.children = [] ; } ; PIXI.DisplayObjectContainer.prototype = Object.create(PIXI.DisplayObject.prototype); PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer; PIXI.DisplayObjectContainer.prototype.addChild = function (child){ this.addChildAt(child, _AN_Read_length('length', this.children)); } ; PIXI.DisplayObjectContainer.prototype.addChildAt = function (child, index){ if (index >= 0 && index <= _AN_Read_length('length', this.children)) { if (child.parent) { child.parent.removeChild(child); } child.parent = this; this.children.splice(index, 0, child); if (this.stage) child.setStageReference(this.stage); } else { throw new Error(child + ' The index ' + index + ' supplied is out of bounds ' + (_AN_Read_length('length', this.children))) } } ; PIXI.DisplayObjectContainer.prototype.swapChildren = function (child, child2){ if (child === child2) { return ; } var index1 = this.children.indexOf(child); var index2 = this.children.indexOf(child2); if (index1 < 0 || index2 < 0) { throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller.') } this.children[index1] = child2; this.children[index2] = child; } ; PIXI.DisplayObjectContainer.prototype.getChildAt = function (index){ if (index >= 0 && index < _AN_Read_length('length', this.children)) { return this.children[index]; } else { throw new Error('The supplied DisplayObjects must be a child of the caller ' + this) } } ; PIXI.DisplayObjectContainer.prototype.removeChild = function (child){ var index = this.children.indexOf(child); if (index !== -1) { if (this.stage) child.removeStageReference(); child.parent = undefined; this.children.splice(index, 1); } else { throw new Error(child + ' The supplied DisplayObject must be a child of the caller ' + this) } } ; PIXI.DisplayObjectContainer.prototype.updateTransform = function (){ if (!this.visible) return ; PIXI.DisplayObject.prototype.updateTransform.call(this); for (var i = 0, j = _AN_Read_length('length', this.children); i < j; i++ ){ this.children[i].updateTransform(); } } ; PIXI.DisplayObjectContainer.prototype.getBounds = function (matrix){ if (_AN_Read_length('length', this.children) === 0) return PIXI.EmptyRectangle; if (matrix) { var matrixCache = this.worldTransform; this.worldTransform = matrix; this.updateTransform(); this.worldTransform = matrixCache; } var minX = Infinity; var minY = Infinity; var maxX = - Infinity; var maxY = - Infinity; var childBounds; var childMaxX; var childMaxY; var childVisible = false ; for (var i = 0, j = _AN_Read_length('length', this.children); i < j; i++ ){ var child = this.children[i]; if (!child.visible) continue ; childVisible = true ; childBounds = this.children[i].getBounds(matrix); minX = minX < childBounds.x? minX: childBounds.x; minY = minY < childBounds.y? minY: childBounds.y; childMaxX = childBounds.width + childBounds.x; childMaxY = childBounds.height + childBounds.y; maxX = maxX > childMaxX? maxX: childMaxX; maxY = maxY > childMaxY? maxY: childMaxY; } if (!childVisible) return PIXI.EmptyRectangle; var bounds = this._bounds; bounds.x = minX; bounds.y = minY; bounds.width = maxX - minX; bounds.height = maxY - minY; return bounds; } ; PIXI.DisplayObjectContainer.prototype.getLocalBounds = function (){ var matrixCache = this.worldTransform; this.worldTransform = PIXI.identityMatrix; for (var i = 0, j = _AN_Read_length('length', this.children); i < j; i++ ){ this.children[i].updateTransform(); } var bounds = this.getBounds(); this.worldTransform = matrixCache; return bounds; } ; PIXI.DisplayObjectContainer.prototype.setStageReference = function (stage){ this.stage = stage; if (this._interactive) this.stage.dirty = true ; for (var i = 0, j = _AN_Read_length('length', this.children); i < j; i++ ){ var child = this.children[i]; child.setStageReference(stage); } } ; PIXI.DisplayObjectContainer.prototype.removeStageReference = function (){ for (var i = 0, j = _AN_Read_length('length', this.children); i < j; i++ ){ var child = this.children[i]; child.removeStageReference(); } if (this._interactive) this.stage.dirty = true ; this.stage = null ; } ; PIXI.DisplayObjectContainer.prototype._renderWebGL = function (renderSession){ if (!this.visible || this.alpha <= 0) return ; var i, j; if (this._mask || this._filters) { if (this._mask) { renderSession.spriteBatch.stop(); renderSession.maskManager.pushMask(this.mask, renderSession); renderSession.spriteBatch.start(); } if (this._filters) { renderSession.spriteBatch.flush(); renderSession.filterManager.pushFilter(this._filterBlock); } for (i = 0, j = _AN_Read_length('length', this.children); i < j; i++ ){ this.children[i]._renderWebGL(renderSession); } renderSession.spriteBatch.stop(); if (this._filters) renderSession.filterManager.popFilter(); if (this._mask) renderSession.maskManager.popMask(renderSession); renderSession.spriteBatch.start(); } else { for (i = 0, j = _AN_Read_length('length', this.children); i < j; i++ ){ this.children[i]._renderWebGL(renderSession); } } } ; PIXI.DisplayObjectContainer.prototype._renderCanvas = function (renderSession){ if (this.visible === false || this.alpha === 0) return ; if (this._mask) { renderSession.maskManager.pushMask(this._mask, renderSession.context); } for (var i = 0, j = _AN_Read_length('length', this.children); i < j; i++ ){ var child = this.children[i]; child._renderCanvas(renderSession); } if (this._mask) { renderSession.maskManager.popMask(renderSession.context); } } ;