Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <canvas id="canvas" style="width: 300px; height: 300px;" onclick=toggle()></canvas>
- <script>
- const canvas = document.getElementById("canvas");
- const ctx = canvas.getContext("2d");
- ctx.fillStyle = "black";
- ctx.fillRect(0, 0, 300, 300);
- var locked = false;
- function toggle() {
- console.log("hullo");
- if(locked) {
- document.exitPointerLock();
- } else {
- canvas.requestPointerLock();
- //canvas.requestPointerLock(); //uncomment for crash
- }
- locked = !locked;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment