-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix mouseX/mouseY not updating on canvas resize #8141
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR fixes an issue where mouseX
and mouseY
coordinates were not being updated when the canvas was resized, causing them to become inaccurate relative to the new canvas dimensions.
- Store the last mouse event in
_updateNextMouseCoords()
for later use - Recalculate mouse coordinates during window resize using the stored event
- Ensure mouse coordinates remain accurate after canvas size changes
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/events/mouse.js | Store last mouse event for coordinate recalculation |
src/core/environment.js | Update mouse coordinates on window resize using stored event |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
99a7f99
to
555ba23
Compare
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.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
this._setProperty('windowHeight', getWindowHeight()); | ||
// Update mouse coordinates when window resizes | ||
// This ensures mouseX/mouseY reflect the mouse position relative to the new canvas size | ||
if (this._hasMouseInteracted && this._lastMouseEvent) { |
Copilot
AI
Oct 12, 2025
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.
The condition checks _hasMouseInteracted
but this property may not be initialized. Consider adding a null check or ensuring this property is properly initialized before use.
Copilot uses AI. Check for mistakes.
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.
_hasMouseInteracted is initialized to false on line 117 of mouse.js (p5.prototype._hasMouseInteracted = false;), so it's always defined.
Resolves #8139
Changes:
PR Checklist
npm run lint
passes