pmouseIsPressed should be a p5 variable
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
Increasing Access
pMouseX and pMouseY are p5 variables because they are useful, even though one could code them in. Likewise, pmouseIsPressed would be useful. By looking at pmouseIsPressed and mouseIsPressed, you can tell whether a user has just pressed on the mouse or just released it.
But doesn't mousePressed() and mouseReleased() do that for you?
Yes, but there's two issues. The first is that draw() and mousePressed() (or any mouse function) are two different functions so you have to type values twice. It's hard to explain so I made coding examples. Here is code with pmouseIsPressed and here is code without it.
The second issue is that on my phone, mousePressed() runs twice every time I touch the screen (so does touchStarted()). I don't know why that's the case, but to fix it I code in pmouseIsPressed and use it (like in my first code example). Edit: this is a bug, I reported it as #6030.
For every new program I write I always include pmouseIsPressed. It would be a great addition to the p5 library!
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build Process
- Unit Testing
- Internalization
- Friendly Errors
- Other (specify if possible)
Feature request details
pmouseIsPressed stores the value of whether the mouse was pressed last frame
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading how mouseIsPressed, pmouseX, and pmouseY are updated across draw(), mousePressed(), mouseReleased(), and touchStarted(). Determine how a previous-frame value should be exposed as pmouseIsPressed, then verify that it distinguishes a press, hold, and release without relying on callback functions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100