函數 exitPointerLock() 退出先前使用的指針鎖,例如,如果指針被鎖定,則將其解鎖,反之亦然。用於退出由 requestPointer() 函數調用的指針鎖。
用法:
exitPointerLock()
第一步:打開p5.js的網頁編輯器 https://editor.p5js.org/
第二步:編寫如下代碼,查看結果。
例:
Javascript
// Make a boolean variable and set
// its value false
let lock = false;
// Set the function
function setup() {
// Set the frame rate
frameRate(5);
// Set the canvas size
createCanvas(600, 400, WEBGL);
}
// Set the draw function
function draw() {
// Set the background colour
background(175);
// 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);
ambientLight(255);
rotateX(-movedX * 0.1);
rotateY(movedY * 0.1);
noStroke();
normalMaterial();
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
requestPointerLock();
} else {
// Exit the pointer lock
exitPointerLock();
// Again make te lock variable false
lock = false;
}
}
輸出:
在輸出中,我們可以看到,當鼠標被釋放時,它退出了之前的指針鎖定,因為我們已經設置了 mouseReleased() 函數來退出指針鎖定。
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- Tensorflow.js tf.layers.embedding()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
- PHP stream_get_transports()用法及代碼示例
注:本文由純淨天空篩選整理自_sh_pallavi大神的英文原創作品 p5.js exitPointerLock() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。