-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
fix: make offscreen component able to change the offscreen distance #611
base: master
Are you sure you want to change the base?
fix: make offscreen component able to change the offscreen distance #611
Conversation
commit: |
if (!this.offscreenDistance && this.width && this.height) { | ||
const selfRect = new Rect(pos, this.width, this.height); | ||
return selfRect.collides(screenRect); | ||
} | ||
const sdist = Math.pow(this.offscreenDistance | ||
? this.offscreenDistance | ||
: DEF_OFFSCREEN_DIS, 2); |
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 is not more complexity added?
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.
It only runs for when the offscreen distance is not set and it's a sprite() or rect() or text(), but considering that it allocates a new rect on each frame, I could probably fix that.
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.
Yeah, would be cool. It also adds a way for it working nice by default but I'm worried about that allocation.
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.
Do we really need to use pow? it's just
const sdist = this.offscreenDistance ?
this.offscreenDistance * this.offscreenDistance :
DEF_OFFSCREEN_DIS * DEF_OFFSCREEN_DIS;
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.
But is that faster? If it isn't, I like the shorter solution
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.
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.
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.
Firefox on Mac OS X here.
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.
Guess it must be the processor then. Mine's an M3.
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.
Same on chrome on Mac OS X. No idea why a function call + various calculations gets the same speed as a multiplication on you PC.
if the object size is changed to be greater than the initially specified offscreen distance, then this allows the offscreen distance to be changed so it won't actually disappear until it goes offscreen. additionally the object will use whether its bounding rectangle is truly offscreen if the distance is not specified.