p5.js exitPointerLock() Function
Last Updated :
17 Jan, 2023
The function exitPointerLock() quit the previously used Pointer Lock for example if the pointer is locked then it unlock it and vice-versa. It is used to exit the pointer lock which is called by requestPointer() function.
Syntax:
exitPointerLock()
Step 1: Open the web editor of p5.js https://editor.p5js.org/
Step 2:Write the following code and see the result.
Example:
Javascript
let lock = false ;
function setup() {
frameRate(5);
createCanvas(600, 400, WEBGL);
}
function draw() {
background(175);
let cX = random(-10, 10);
let cY = random(-10, 10);
let cZ = random(-10, 10);
camera(cX, cY,
cZ + (height / 2) / tan(PI / 6),
cX, 0, 0, 0, 1, 0);
ambientLight(255);
rotateX(-movedX * 0.1);
rotateY(movedY * 0.1);
noStroke();
normalMaterial();
box(100, 100, 100);
}
function mouseReleased() {
if (!lock) {
lock = true ;
requestPointerLock();
} else {
exitPointerLock();
lock = false ;
}
}
|
Output:
In output, we can see that when the mouse is released it exit the previous pointer lock because we have set the mouseReleased() function to exit the pointer lock.
Share your thoughts in the comments
Please Login to comment...