diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 71b49d4..cb24968 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -373,7 +373,7 @@ this._width = this.canvas.width / this.resolution; this._height = this.canvas.height / this.resolution; - texture.update(); + texture.baseTexture.emit('update', texture.baseTexture); this.dirty = false; }; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 71b49d4..cb24968 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -373,7 +373,7 @@ this._width = this.canvas.width / this.resolution; this._height = this.canvas.height / this.resolution; - texture.update(); + texture.baseTexture.emit('update', texture.baseTexture); this.dirty = false; }; diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 32b1172..4c3809c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -164,12 +164,20 @@ module.exports = BaseTexture; /** - * Updates the texture on all the webgl renderers. + * Updates the texture on all the webgl renderers this also assumes the src has changed. * * @fires update */ BaseTexture.prototype.update = function () { + this.realWidth = this.source.naturalWidth || this.source.width; + this.realHeight = this.source.naturalHeight || this.source.height; + + this.width = this.realWidth / this.resolution; + this.height = this.realHeight / this.resolution; + + this.isPowerOfTwo = utils.isPowerOfTwo(this.width, this.height); + this.emit('update', this); }; @@ -296,16 +304,6 @@ BaseTexture.prototype._sourceLoaded = function () { this.hasLoaded = true; - - this.realWidth = this.source.naturalWidth || this.source.width; - this.realHeight = this.source.naturalHeight || this.source.height; - - this.width = this.realWidth / this.resolution; - this.height = this.realHeight / this.resolution; - - - this.isPowerOfTwo = utils.isPowerOfTwo(this.width, this.height); - this.update(); }; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 71b49d4..cb24968 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -373,7 +373,7 @@ this._width = this.canvas.width / this.resolution; this._height = this.canvas.height / this.resolution; - texture.update(); + texture.baseTexture.emit('update', texture.baseTexture); this.dirty = false; }; diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index 32b1172..4c3809c 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -164,12 +164,20 @@ module.exports = BaseTexture; /** - * Updates the texture on all the webgl renderers. + * Updates the texture on all the webgl renderers this also assumes the src has changed. * * @fires update */ BaseTexture.prototype.update = function () { + this.realWidth = this.source.naturalWidth || this.source.width; + this.realHeight = this.source.naturalHeight || this.source.height; + + this.width = this.realWidth / this.resolution; + this.height = this.realHeight / this.resolution; + + this.isPowerOfTwo = utils.isPowerOfTwo(this.width, this.height); + this.emit('update', this); }; @@ -296,16 +304,6 @@ BaseTexture.prototype._sourceLoaded = function () { this.hasLoaded = true; - - this.realWidth = this.source.naturalWidth || this.source.width; - this.realHeight = this.source.naturalHeight || this.source.height; - - this.width = this.realWidth / this.resolution; - this.height = this.realHeight / this.resolution; - - - this.isPowerOfTwo = utils.isPowerOfTwo(this.width, this.height); - this.update(); }; diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 09630c6..fd8bf23 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -128,6 +128,9 @@ if (this.noFrame) { frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); + + // if there is no frame we should monitor for any base texture changes.. + baseTexture.on('update', this.onBaseTextureUpdated, this); } this.frame = frame; } @@ -194,8 +197,6 @@ Texture.prototype.update = function () { this.baseTexture.update(); - - }; /** @@ -218,6 +219,14 @@ this.emit( 'update', this ); }; +Texture.prototype.onBaseTextureUpdated = function (baseTexture) +{ + this._frame.width = baseTexture.width; + this._frame.height = baseTexture.height; + + this.emit( 'update', this ); +}; + /** * Destroys this texture * @@ -230,6 +239,9 @@ this.baseTexture.destroy(); } + baseTexture.remove('update', this.onBaseTextureUpdated, this); + baseTexture.remove('loaded', this.onBaseTextureLoaded, this); + this.valid = false; };