diff --git a/js/rpg_core/Bitmap.js b/js/rpg_core/Bitmap.js index 78955139..539861ef 100644 --- a/js/rpg_core/Bitmap.js +++ b/js/rpg_core/Bitmap.js @@ -758,7 +758,7 @@ Bitmap.prototype._onLoad = function() { Bitmap.prototype._callLoadListeners = function() { while (this._loadListeners.length > 0) { var listener = this._loadListeners.shift(); - listener(); + listener(this); } }; diff --git a/js/rpg_core/Sprite.js b/js/rpg_core/Sprite.js index c7ce77c1..54fcd53c 100644 --- a/js/rpg_core/Sprite.js +++ b/js/rpg_core/Sprite.js @@ -57,13 +57,17 @@ Object.defineProperty(Sprite.prototype, 'bitmap', { }, set: function(value) { if (this._bitmap !== value) { - this._bitmap = value; - if (this._bitmap) { - this.setFrame(0, 0, 0, 0); - this._bitmap.addLoadListener(this._onBitmapLoad.bind(this)); - } else { + if(!this._bitmap){ + this._refreshFrame = true; + }else if(this._bitmap && value){ + this._refreshFrame = false; + }else if(!value){ + this._refreshFrame = false; this.texture.frame = Rectangle.emptyRectangle; } + + this._bitmap = value; + if(value)value.addLoadListener(this._onBitmapLoad.bind(this)); } }, configurable: true @@ -221,11 +225,15 @@ Sprite.prototype.setColorTone = function(tone) { * @method _onBitmapLoad * @private */ -Sprite.prototype._onBitmapLoad = function() { - if (this._frame.width === 0 && this._frame.height === 0) { - this._frame.width = this._bitmap.width; - this._frame.height = this._bitmap.height; +Sprite.prototype._onBitmapLoad = function(bitmapLoaded) { + if(bitmapLoaded === this._bitmap){ + if (this._refreshFrame && this._bitmap) { + this._refreshFrame = false; + this._frame.width = this._bitmap.width; + this._frame.height = this._bitmap.height; + } } + this._refresh(); };