Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Feb 11, 2017

This fix bug wrote in Title.

@ghost ghost added this to the 1.1 milestone Feb 11, 2017
Sprite.prototype._isInBitmapRect = function(x, y, w, h) {
return (this._bitmap && x + w > 0 && y + h > 0 &&
x < this._bitmap.width && y < this._bitmap.height);
x < this._bitmap.width && y < this._bitmap.height);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Found format-only changes! :-)

Copy link
Author

Choose a reason for hiding this comment

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

OK fixed it.

if (this._frame.width === 0 && this._frame.height === 0) {
this._frame.width = this._bitmap.width;
this._frame.height = this._bitmap.height;
if(this._requestBitmap === 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.

I don't know why this._requestBitmap is defined, because it's always the same as this._bitmap.

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 is some chance to change Bitmap while loading is not completed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Of course it's async, so bitmap may be changed.
But... this._requestBitmap is changed at the same time. (69-70)
So, this condition-expression will always be true.

Copy link
Author

Choose a reason for hiding this comment

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

Oops you are right.
Something went wrong, I'll re-test it.

@krmbn0576
Copy link
Collaborator

I found a description similar to TillingSprite#bitmap(set). Would you like to change it the same way?

@ghost
Copy link
Author

ghost commented Feb 12, 2017

TilingSprite is already guarded by line: 183
I think this is enough.

@krmbn0576
Copy link
Collaborator

OH, really?
If so, why not Sprite as well??
It's one-line!

@ghost
Copy link
Author

ghost commented Feb 12, 2017

Sprite needs clearing frame, This can cause showing entire frame.
so I defer clearing frame until Bitmap will load.

@krmbn0576
Copy link
Collaborator

Hmm, I still don't understand your intentions.
What situations do you want to avoid?

In this code, frame is refreshed when bitmap changes null to non-null.
frame is never changed when bitmap changes non-null to anything.
Is this behavior correct?

@ghost
Copy link
Author

ghost commented Feb 16, 2017

I deferred only clearing entire frame.
updating frame is done by _refresh

} 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._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.

Copy link
Collaborator

@krmbn0576 krmbn0576 left a comment

Choose a reason for hiding this comment

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

OK, LGTM! 🍣

@ghost ghost merged commit 5a95385 into master Feb 18, 2017
@ghost ghost deleted the fix-sprite branch February 18, 2017 08:37
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant