Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dragoncoder047
Copy link
Contributor

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.

Copy link

pkg-pr-new bot commented Feb 17, 2025

Open in Stackblitz

npm i https://pkg.pr.new/kaplayjs/kaplay@611

commit: 233d829

Comment on lines 101 to 107
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);
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Member

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;

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Screenshot 2025-03-04 at 8 56 42

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oof, your browser...

This is what I get (and In Firefox, nonetheless...):

Screenshot 2025-03-03 at 6 58 21 PM

Copy link
Member

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.

Copy link
Contributor Author

@dragoncoder047 dragoncoder047 Mar 4, 2025

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.

Copy link
Member

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.

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.

3 participants