function onClickListenerFrame() {
      // Only reschedule the loop if a display is still presenting.
      if (presentingDisplay && presentingDisplay.isPresenting) {
        presentingDisplay.requestAnimationFrame(onClickListenerFrame);
      }
      
      let gamepads = navigator.getGamepads();
      for (let i = 0; i < gamepads.length; ++i) {
        let gamepad = gamepads[i];
        // Ensure the gamepad is valid and has buttons.
        if (gamepad &&
            gamepad.buttons.length) {
          let lastState = lastButtonState[i] || false;
          let newState = gamepad.buttons[0].pressed;
          // If the primary button state has changed from not pressed to pressed 
          // over the last frame then fire the callback.
          if (newState && !lastState) {
            clickCallback(gamepad);
          }
          lastButtonState[i] = newState;
        }
      }
    }
// Set up a loop to check gamepad state while any VRDisplay is presenting.
Set up a loop to check gamepad state while any VRDisplay is presenting.
Set up a loop to check gamepad state while any VRDisplay is presenting .
function onClickListenerFrame() {
      if (presentingDisplay && presentingDisplay.isPresenting) {
        presentingDisplay.requestAnimationFrame(onClickListenerFrame);
      }
      let gamepads = navigator.getGamepads();
      for (let i = 0; i < gamepads.length; ++i) {
        let gamepad = gamepads[i];
        if (gamepad &&
            gamepad.buttons.length) {
          let lastState = lastButtonState[i] || false;
          let newState = gamepad.buttons[0].pressed;
          if (newState && !lastState) {
            clickCallback(gamepad);
          }
          lastButtonState[i] = newState;
        }
      }
    }
function onClickListenerFrame ( ) { if ( presentingDisplay && presentingDisplay . isPresenting ) { presentingDisplay . requestAnimationFrame ( onClickListenerFrame ) ; } let gamepads = navigator . getGamepads ( ) ; for ( let i = 0 ; i < gamepads . length ; ++ i ) { let gamepad = gamepads [ i ] ; if ( gamepad && gamepad . buttons . length ) { let lastState = lastButtonState [ i ] || false ; let newState = gamepad . buttons [ 0 ] . pressed ; if ( newState && ! lastState ) { clickCallback ( gamepad ) ; } lastButtonState [ i ] = newState ; } } }
Set up a loop to check gamepad state while any VRDisplay is presenting.
Set up a loop to check gamepad state while any VRDisplay is presenting .
// Only reschedule the loop if a display is still presenting. // Ensure the gamepad is valid and has buttons. // If the primary button state has changed from not pressed to pressed  // over the last frame then fire the callback.