diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 0791830..949aab7 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -128,6 +128,9 @@ { baseTexture.once('loaded', this.onBaseTextureLoaded, this); } + + // the base texture is updated we may need to update our frame + baseTexture.on('update', this.onBaseTextureLoaded, this); } Texture.prototype = Object.create(EventEmitter.prototype); @@ -149,8 +152,6 @@ this.width = frame.width; this.height = frame.height; - - if (!this.trim && !this.rotate && (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); @@ -172,16 +173,18 @@ this.crop = frame; } - if (this.valid) + if (this.valid) { this._updateUvs(); } + + this.emit('update', this); } } }); /** - * Updates this texture on the gpu. + * Updates this texture for drawing. * */ Texture.prototype.update = function () @@ -196,17 +199,18 @@ */ Texture.prototype.onBaseTextureLoaded = function (baseTexture) { - // TODO this code looks confusing.. boo to abusing getters and setterss! + baseTexture = baseTexture || this.baseTexture; + + // if no frame then create one and run the frame setter if (this.noFrame) { this.frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); } + // otherwise rerun the frame setter with the current frame to check for baseTexture validity else { this.frame = this._frame; } - - this.emit( 'update', this ); }; /**