Skip to content

Commit 5a95385

Browse files
author
liply
authored
Merge pull request #20 from rpgtkoolmv/fix-sprite
fix null reference and shows entire frame bug.
2 parents 4179d69 + 42421a1 commit 5a95385

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

js/rpg_core/Bitmap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ Bitmap.prototype._onLoad = function() {
758758
Bitmap.prototype._callLoadListeners = function() {
759759
while (this._loadListeners.length > 0) {
760760
var listener = this._loadListeners.shift();
761-
listener();
761+
listener(this);
762762
}
763763
};
764764

js/rpg_core/Sprite.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ Object.defineProperty(Sprite.prototype, 'bitmap', {
5757
},
5858
set: function(value) {
5959
if (this._bitmap !== value) {
60-
this._bitmap = value;
61-
if (this._bitmap) {
62-
this.setFrame(0, 0, 0, 0);
63-
this._bitmap.addLoadListener(this._onBitmapLoad.bind(this));
64-
} else {
60+
if(!this._bitmap){
61+
this._refreshFrame = true;
62+
}else if(this._bitmap && value){
63+
this._refreshFrame = false;
64+
}else if(!value){
65+
this._refreshFrame = false;
6566
this.texture.frame = Rectangle.emptyRectangle;
6667
}
68+
69+
this._bitmap = value;
70+
if(value)value.addLoadListener(this._onBitmapLoad.bind(this));
6771
}
6872
},
6973
configurable: true
@@ -221,11 +225,15 @@ Sprite.prototype.setColorTone = function(tone) {
221225
* @method _onBitmapLoad
222226
* @private
223227
*/
224-
Sprite.prototype._onBitmapLoad = function() {
225-
if (this._frame.width === 0 && this._frame.height === 0) {
226-
this._frame.width = this._bitmap.width;
227-
this._frame.height = this._bitmap.height;
228+
Sprite.prototype._onBitmapLoad = function(bitmapLoaded) {
229+
if(bitmapLoaded === this._bitmap){
230+
if (this._refreshFrame && this._bitmap) {
231+
this._refreshFrame = false;
232+
this._frame.width = this._bitmap.width;
233+
this._frame.height = this._bitmap.height;
234+
}
228235
}
236+
229237
this._refresh();
230238
};
231239

0 commit comments

Comments
 (0)