Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/rpg_core/Bitmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
26 changes: 17 additions & 9 deletions js/rpg_core/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition-expression can be written shorter.
Written long for readability?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I prefer self-descriptive code.

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
Expand Down Expand Up @@ -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) {
Copy link
Collaborator

@krmbn0576 krmbn0576 Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this._bitmap is always non-null because it equals bitmapLoaded.
So, it's enough if (this._refreshFrame)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope onBitmapLoad is async. there are some chance bitmapLoaded !== this._bitmap

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I talked about line 230 only.
I thought && this._bitmap isn't necessary because it's always non-null.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If We approve your suggestion, The reader must know about behavior of bitmapLoaded.

this._refreshFrame = false;
this._frame.width = this._bitmap.width;
this._frame.height = this._bitmap.height;
}
}

this._refresh();
};

Expand Down