Skip to content

Conversation

@Cocomwana
Copy link

Hello,

Added a pointer.hmd.md file but unfortunately could not find a snippet that was simple enough.

Cheers

Done as part as 24PR @codebar

@BPScott
Copy link
Collaborator

BPScott commented Dec 5, 2015

Hi @Cocomwana, thanks for taking the time to contribute!

I'd like to keep the trend of having code examples on each page. Taking a look at the MDN demo it looks like a minimal demo could be something like (I've not tested this!):

var htmlElem = document.querySelector('html');

htmlElem.requestPointerLock = htmlElem.requestPointerLock ||
           htmlElem.mozRequestPointerLock ||
           htmlElem.webkitRequestPointerLock;

htmlElem.onclick = function() {
  htmlElem.requestPointerLock();
}

// pointer lock event listeners

// Hook pointer lock state change events for different browsers
document.addEventListener('pointerlockchange', lockChangeAlert, false);
document.addEventListener('mozpointerlockchange', lockChangeAlert, false);
document.addEventListener('webkitpointerlockchange', lockChangeAlert, false);

function lockChangeAlert() {
  if(document.pointerLockElement === htmlElem ||
  document.mozPointerLockElement === htmlElem ||
  document.webkitPointerLockElement === htmlElem) {
    console.log('The pointer lock status is now locked');
    document.addEventListener("mousemove", htmlElemLoop, false);
  } else {
    console.log('The pointer lock status is now unlocked');
    document.removeEventListener("mousemove", htmlElemLoop, false);
  }
}

function htmlElemLoop(e) {
  var movementX = e.movementX || e.mozMovementX || e.webkitMovementX || 0;
  var movementY = e.movementY || e.mozMovementY || e.webkitMovementY || 0;

  console.log(movementX, movementY);
}

Could you check if that code works (use http://codepen.io or something to that effect) and add it to the PR (with along with any fixes that need to be made because I fail at copy+pasting code).

@BPScott
Copy link
Collaborator

BPScott commented Dec 5, 2015

Linking comment, this is a PR for #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants