-
Notifications
You must be signed in to change notification settings - Fork 74
fix null reference and shows entire frame bug. #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope onBitmapLoad is async. there are some chance
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, I talked about line 230 only.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.