diff --git a/src/core/const.js b/src/core/const.js index aea72ec..35beb03 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -145,10 +145,10 @@ * @property {object} SHAPES.RREC=4 */ SHAPES: { - POLY = 0; - RECT = 1; - CIRC = 2; - ELIP = 3; - RREC = 4; + POLY: 0, + RECT: 1, + CIRC: 2, + ELIP: 3, + RREC: 4 } }; diff --git a/src/core/const.js b/src/core/const.js index aea72ec..35beb03 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -145,10 +145,10 @@ * @property {object} SHAPES.RREC=4 */ SHAPES: { - POLY = 0; - RECT = 1; - CIRC = 2; - ELIP = 3; - RREC = 4; + POLY: 0, + RECT: 1, + CIRC: 2, + ELIP: 3, + RREC: 4 } }; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index cae626a..182d242 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,4 @@ -var math = require('../math'), - _tempMatrix = new math.Matrix(); +var math = require('../math'); /** * The base class for all objects that are rendered on the screen. diff --git a/src/core/const.js b/src/core/const.js index aea72ec..35beb03 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -145,10 +145,10 @@ * @property {object} SHAPES.RREC=4 */ SHAPES: { - POLY = 0; - RECT = 1; - CIRC = 2; - ELIP = 3; - RREC = 4; + POLY: 0, + RECT: 1, + CIRC: 2, + ELIP: 3, + RREC: 4 } }; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index cae626a..182d242 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,4 @@ -var math = require('../math'), - _tempMatrix = new math.Matrix(); +var math = require('../math'); /** * The base class for all objects that are rendered on the screen. diff --git a/src/core/display/DisplayObjectContainer.js b/src/core/display/DisplayObjectContainer.js index d76b7f2..4b0bfc9 100644 --- a/src/core/display/DisplayObjectContainer.js +++ b/src/core/display/DisplayObjectContainer.js @@ -1,7 +1,8 @@ var math = require('../math'), DisplayObject = require('./DisplayObject'), RenderTexture = require('../textures/RenderTexture'), - Sprite = require('./Sprite'); + Sprite = require('./Sprite'), + _tempMatrix = new math.Matrix(); /** * A DisplayObjectContainer represents a collection of display objects. @@ -29,6 +30,8 @@ * @private */ this._cacheAsBitmap = false; + + this._cachedSprite = null; } // constructor @@ -283,7 +286,7 @@ * Generates and updates the cached sprite for this object. * */ -DisplayObjectContainer.prototype.updateCache = function () { +DisplayObjectContainer.prototype.updateCachedSprite = function () { this._generateCachedSprite(); }; @@ -528,7 +531,6 @@ * @private */ DisplayObjectContainer.prototype._generateCachedSprite = function () { - this._cacheAsBitmap = false; var bounds = this.getLocalBounds(); if (!this._cachedSprite) { @@ -541,7 +543,6 @@ this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); } - // REMOVE filter! var tempFilters = this._filters; this._filters = null; @@ -556,8 +557,6 @@ this._cachedSprite.anchor.y = -(bounds.y / bounds.height); this._filters = tempFilters; - - this._cacheAsBitmap = true; }; /** @@ -570,8 +569,7 @@ return; } - this._cachedSprite.texture.destroy(true); - - // TODO could be object pooled! + // TODO: Pool this sprite + this._cachedSprite.destroy(true, true); this._cachedSprite = null; }; diff --git a/src/core/const.js b/src/core/const.js index aea72ec..35beb03 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -145,10 +145,10 @@ * @property {object} SHAPES.RREC=4 */ SHAPES: { - POLY = 0; - RECT = 1; - CIRC = 2; - ELIP = 3; - RREC = 4; + POLY: 0, + RECT: 1, + CIRC: 2, + ELIP: 3, + RREC: 4 } }; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index cae626a..182d242 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,4 @@ -var math = require('../math'), - _tempMatrix = new math.Matrix(); +var math = require('../math'); /** * The base class for all objects that are rendered on the screen. diff --git a/src/core/display/DisplayObjectContainer.js b/src/core/display/DisplayObjectContainer.js index d76b7f2..4b0bfc9 100644 --- a/src/core/display/DisplayObjectContainer.js +++ b/src/core/display/DisplayObjectContainer.js @@ -1,7 +1,8 @@ var math = require('../math'), DisplayObject = require('./DisplayObject'), RenderTexture = require('../textures/RenderTexture'), - Sprite = require('./Sprite'); + Sprite = require('./Sprite'), + _tempMatrix = new math.Matrix(); /** * A DisplayObjectContainer represents a collection of display objects. @@ -29,6 +30,8 @@ * @private */ this._cacheAsBitmap = false; + + this._cachedSprite = null; } // constructor @@ -283,7 +286,7 @@ * Generates and updates the cached sprite for this object. * */ -DisplayObjectContainer.prototype.updateCache = function () { +DisplayObjectContainer.prototype.updateCachedSprite = function () { this._generateCachedSprite(); }; @@ -528,7 +531,6 @@ * @private */ DisplayObjectContainer.prototype._generateCachedSprite = function () { - this._cacheAsBitmap = false; var bounds = this.getLocalBounds(); if (!this._cachedSprite) { @@ -541,7 +543,6 @@ this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); } - // REMOVE filter! var tempFilters = this._filters; this._filters = null; @@ -556,8 +557,6 @@ this._cachedSprite.anchor.y = -(bounds.y / bounds.height); this._filters = tempFilters; - - this._cacheAsBitmap = true; }; /** @@ -570,8 +569,7 @@ return; } - this._cachedSprite.texture.destroy(true); - - // TODO could be object pooled! + // TODO: Pool this sprite + this._cachedSprite.destroy(true, true); this._cachedSprite = null; }; diff --git a/src/core/display/Sprite.js b/src/core/display/Sprite.js index f05db8a..4830cd0 100644 --- a/src/core/display/Sprite.js +++ b/src/core/display/Sprite.js @@ -79,11 +79,25 @@ */ this.shader = null; - this.texture = texture || Texture.EMPTY; - this.renderable = true; + + // call texture setter + this.texture = texture || Texture.EMPTY; } +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) { + DisplayObjectContainer.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // constructor Sprite.prototype = Object.create(DisplayObjectContainer.prototype); Sprite.prototype.constructor = Sprite; diff --git a/src/core/const.js b/src/core/const.js index aea72ec..35beb03 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -145,10 +145,10 @@ * @property {object} SHAPES.RREC=4 */ SHAPES: { - POLY = 0; - RECT = 1; - CIRC = 2; - ELIP = 3; - RREC = 4; + POLY: 0, + RECT: 1, + CIRC: 2, + ELIP: 3, + RREC: 4 } }; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index cae626a..182d242 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,4 @@ -var math = require('../math'), - _tempMatrix = new math.Matrix(); +var math = require('../math'); /** * The base class for all objects that are rendered on the screen. diff --git a/src/core/display/DisplayObjectContainer.js b/src/core/display/DisplayObjectContainer.js index d76b7f2..4b0bfc9 100644 --- a/src/core/display/DisplayObjectContainer.js +++ b/src/core/display/DisplayObjectContainer.js @@ -1,7 +1,8 @@ var math = require('../math'), DisplayObject = require('./DisplayObject'), RenderTexture = require('../textures/RenderTexture'), - Sprite = require('./Sprite'); + Sprite = require('./Sprite'), + _tempMatrix = new math.Matrix(); /** * A DisplayObjectContainer represents a collection of display objects. @@ -29,6 +30,8 @@ * @private */ this._cacheAsBitmap = false; + + this._cachedSprite = null; } // constructor @@ -283,7 +286,7 @@ * Generates and updates the cached sprite for this object. * */ -DisplayObjectContainer.prototype.updateCache = function () { +DisplayObjectContainer.prototype.updateCachedSprite = function () { this._generateCachedSprite(); }; @@ -528,7 +531,6 @@ * @private */ DisplayObjectContainer.prototype._generateCachedSprite = function () { - this._cacheAsBitmap = false; var bounds = this.getLocalBounds(); if (!this._cachedSprite) { @@ -541,7 +543,6 @@ this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); } - // REMOVE filter! var tempFilters = this._filters; this._filters = null; @@ -556,8 +557,6 @@ this._cachedSprite.anchor.y = -(bounds.y / bounds.height); this._filters = tempFilters; - - this._cacheAsBitmap = true; }; /** @@ -570,8 +569,7 @@ return; } - this._cachedSprite.texture.destroy(true); - - // TODO could be object pooled! + // TODO: Pool this sprite + this._cachedSprite.destroy(true, true); this._cachedSprite = null; }; diff --git a/src/core/display/Sprite.js b/src/core/display/Sprite.js index f05db8a..4830cd0 100644 --- a/src/core/display/Sprite.js +++ b/src/core/display/Sprite.js @@ -79,11 +79,25 @@ */ this.shader = null; - this.texture = texture || Texture.EMPTY; - this.renderable = true; + + // call texture setter + this.texture = texture || Texture.EMPTY; } +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) { + DisplayObjectContainer.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // constructor Sprite.prototype = Object.create(DisplayObjectContainer.prototype); Sprite.prototype.constructor = Sprite; diff --git a/src/core/renderers/webgl/utils/WebGLGraphics.js b/src/core/renderers/webgl/utils/WebGLGraphics.js index 1d1fe40..be6ad48 100644 --- a/src/core/renderers/webgl/utils/WebGLGraphics.js +++ b/src/core/renderers/webgl/utils/WebGLGraphics.js @@ -1,5 +1,6 @@ var utils = require('../../../utils'), math = require('../../../math'), + CONST = require('../../../const'), WebGLGraphicsData = require('./WebGLGraphicsData'); /** diff --git a/src/core/const.js b/src/core/const.js index aea72ec..35beb03 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -145,10 +145,10 @@ * @property {object} SHAPES.RREC=4 */ SHAPES: { - POLY = 0; - RECT = 1; - CIRC = 2; - ELIP = 3; - RREC = 4; + POLY: 0, + RECT: 1, + CIRC: 2, + ELIP: 3, + RREC: 4 } }; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index cae626a..182d242 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,5 +1,4 @@ -var math = require('../math'), - _tempMatrix = new math.Matrix(); +var math = require('../math'); /** * The base class for all objects that are rendered on the screen. diff --git a/src/core/display/DisplayObjectContainer.js b/src/core/display/DisplayObjectContainer.js index d76b7f2..4b0bfc9 100644 --- a/src/core/display/DisplayObjectContainer.js +++ b/src/core/display/DisplayObjectContainer.js @@ -1,7 +1,8 @@ var math = require('../math'), DisplayObject = require('./DisplayObject'), RenderTexture = require('../textures/RenderTexture'), - Sprite = require('./Sprite'); + Sprite = require('./Sprite'), + _tempMatrix = new math.Matrix(); /** * A DisplayObjectContainer represents a collection of display objects. @@ -29,6 +30,8 @@ * @private */ this._cacheAsBitmap = false; + + this._cachedSprite = null; } // constructor @@ -283,7 +286,7 @@ * Generates and updates the cached sprite for this object. * */ -DisplayObjectContainer.prototype.updateCache = function () { +DisplayObjectContainer.prototype.updateCachedSprite = function () { this._generateCachedSprite(); }; @@ -528,7 +531,6 @@ * @private */ DisplayObjectContainer.prototype._generateCachedSprite = function () { - this._cacheAsBitmap = false; var bounds = this.getLocalBounds(); if (!this._cachedSprite) { @@ -541,7 +543,6 @@ this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0); } - // REMOVE filter! var tempFilters = this._filters; this._filters = null; @@ -556,8 +557,6 @@ this._cachedSprite.anchor.y = -(bounds.y / bounds.height); this._filters = tempFilters; - - this._cacheAsBitmap = true; }; /** @@ -570,8 +569,7 @@ return; } - this._cachedSprite.texture.destroy(true); - - // TODO could be object pooled! + // TODO: Pool this sprite + this._cachedSprite.destroy(true, true); this._cachedSprite = null; }; diff --git a/src/core/display/Sprite.js b/src/core/display/Sprite.js index f05db8a..4830cd0 100644 --- a/src/core/display/Sprite.js +++ b/src/core/display/Sprite.js @@ -79,11 +79,25 @@ */ this.shader = null; - this.texture = texture || Texture.EMPTY; - this.renderable = true; + + // call texture setter + this.texture = texture || Texture.EMPTY; } +Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) { + DisplayObjectContainer.prototype.destroy.call(this); + + this.anchor = null; + + if (destroyTexture) { + this._texture.destroy(destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + // constructor Sprite.prototype = Object.create(DisplayObjectContainer.prototype); Sprite.prototype.constructor = Sprite; diff --git a/src/core/renderers/webgl/utils/WebGLGraphics.js b/src/core/renderers/webgl/utils/WebGLGraphics.js index 1d1fe40..be6ad48 100644 --- a/src/core/renderers/webgl/utils/WebGLGraphics.js +++ b/src/core/renderers/webgl/utils/WebGLGraphics.js @@ -1,5 +1,6 @@ var utils = require('../../../utils'), math = require('../../../math'), + CONST = require('../../../const'), WebGLGraphicsData = require('./WebGLGraphicsData'); /** diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index d461ece..152524f 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -45,8 +45,9 @@ * The frame specifies the region of the base texture that this texture uses * * @member {Rectangle} + * @private */ - this.frame = frame; + this._frame = frame; /** * The texture trim data. @@ -103,7 +104,7 @@ if (this.noFrame) { frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); } - this.setFrame(frame); + this.frame = frame; } else { baseTexture.addEventListener('loaded', this.onBaseTextureLoaded.bind(this)); @@ -123,6 +124,42 @@ set: function (val) { this.baseTexture.needsUpdate = val; } + }, + + frame: { + get: function () { + return this._frame; + }, + set: function (frame) { + this._frame = frame; + + this.noFrame = false; + + this.width = frame.width; + this.height = frame.height; + + this.crop.x = frame.x; + this.crop.y = frame.y; + this.crop.width = frame.width; + this.crop.height = frame.height; + + if (!this.trim && (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height)) { + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); + } + + this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + + if (this.trim) { + this.width = this.trim.width; + this.height = this.trim.height; + this._frame.width = this.trim.width; + this._frame.height = this.trim.height; + } + + if (this.valid) { + this._updateUvs(); + } + } } }); @@ -139,8 +176,6 @@ this.frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); } - this.setFrame(this.frame); - this.dispatchEvent( { type: 'update', content: this } ); }; @@ -158,42 +193,6 @@ }; /** - * Specifies the region of the baseTexture that this texture will use. - * - * @param frame {Rectangle} The frame of the texture to set it to - */ -Texture.prototype.setFrame = function (frame) { - this.noFrame = false; - - this.frame = frame; - this.width = frame.width; - this.height = frame.height; - - this.crop.x = frame.x; - this.crop.y = frame.y; - this.crop.width = frame.width; - this.crop.height = frame.height; - - if (!this.trim && (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height)) { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - - if (this.trim) { - this.width = this.trim.width; - this.height = this.trim.height; - this.frame.width = this.trim.width; - this.frame.height = this.trim.height; - } - - if (this.valid) { - this._updateUvs(); - } - -}; - -/** * Updates the internal WebGL UV cache. * * @private