Skip to content

Commit 36668ba

Browse files
committed
Added manual test for movedX/Y and requestPointerLock
1 parent c0b5418 commit 36668ba

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/events/mouse.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import * as constants from '../core/constants';
2121
* <a href="#/p5/requestPointerLock">requestPointerLock()</a> is active.
2222
* But keep in mind that during an active pointer lock, mouseX and pmouseX
2323
* are not locked, so `movedX` is based on
24-
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX">the MouseEvent's movementX</a>
25-
* value. This value may behave different in different browsers when the user
26-
* is zoomed in or out.
24+
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX">the MouseEvent's movementX value</a>
25+
* (which may behave differently in different browsers when the user
26+
* is zoomed in or out).
2727
*
2828
* @property {Number} movedX
2929
* @readOnly
@@ -835,7 +835,7 @@ p5.prototype._updateNextMouseCoords = function(e) {
835835
}
836836
else {
837837
// Because mouseX/Y and pmouseX/Y are locked, the elements movementX/Y
838-
// is used for movedX/Y - this maz behave differently on different
838+
// is used for movedX/Y - this may behave differently on different
839839
// browsers at different zoom levels.
840840
this._setProperty('movedX', e.movementX);
841841
this._setProperty('movedY', e.movementY);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script language="javascript" type="text/javascript" src="../../../../lib/p5.js"></script>
5+
</head>
6+
7+
<body>
8+
<h1>Manual test for movedX/Y with/without zoom and with/without pointer lock</h1>
9+
<ul>
10+
<li>If you move the mouse around, you should see 1 moving circle and 1 still. While <strong>dragging mouse</strong>, they should move at the same rate.</li>
11+
<li>After zooming in/out, on all browsers, the circles should still move visually a constant distance relative to each other.</li>
12+
<li>Press any key to request pointer lock. Background will be pink if and only if pointer is locked. Now, if you <strong>drag the mouse</strong>, the small circle should be static (because mouseX/Y are locked) and the big circle should move unsurprisingly.</li>
13+
</ul>
14+
<script language="javascript" type="text/javascript" src="sketch.js"></script>
15+
</body>
16+
</html>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function setup() {
2+
createCanvas(400, 400);
3+
}
4+
5+
let x = 200;
6+
let y = 200;
7+
function draw() {
8+
if (document.pointerLockElement === null){
9+
background(220);
10+
} else{
11+
background(200,0,200);
12+
}
13+
14+
text(movedX, 20, 20);
15+
text(movedY, 20, 40);
16+
text(mouseX, 50, 20);
17+
text(mouseY, 50, 40);
18+
circle(mouseX, mouseY, 30);
19+
20+
//https://editor.p5js.org/SableRaf/sketches/zAXl3tNm5
21+
if(mouseIsPressed){
22+
x += movedX;
23+
y += movedY;
24+
}
25+
26+
circle(x, y, 50);
27+
28+
}
29+
function keyPressed() {
30+
requestPointerLock();
31+
}

0 commit comments

Comments
 (0)