Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

p5.js exitPointerLock() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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.



Step 1: Open the web editor of p5.js

Step 2:Write the following code and see the result.



// Make a boolean variable and set
// its value false
let lock = false;
// Set the function
function setup() {
    // Set the frame rate
    // Set the canvas size
    createCanvas(600, 400, WEBGL);
// Set the draw function
function draw() {
    // Set the background colour
    // Set the camera
    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);
    rotateX(-movedX * 0.1);
    rotateY(movedY * 0.1);
    box(100, 100, 100);
// Function to apply exitpointer lock
function mouseReleased() {
    // If lock is not false then
    // make it true
    if (!lock) {
        lock = true;
        // Request for pointer lock
    } else {
        // Exit the pointer lock
        // Again make the lock variable false
        lock = false;


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.

My Personal Notes arrow_drop_up
Last Updated : 17 Jan, 2023
Like Article
Save Article
Similar Reads
Related Tutorials