joystick-pre.js 749 B

1234567891011121314151617181920212223242526
  1. Module['arguments'] = ['0'];
  2. //Gamepads don't appear until a button is pressed and the joystick/gamepad tests expect one to be connected
  3. Module['preRun'].push(function()
  4. {
  5. Module['print']("Waiting for gamepad...");
  6. Module['addRunDependency']("gamepad");
  7. window.addEventListener('gamepadconnected', function()
  8. {
  9. //OK, got one
  10. Module['removeRunDependency']("gamepad");
  11. }, false);
  12. //chrome
  13. if(!!navigator.webkitGetGamepads)
  14. {
  15. var timeout = function()
  16. {
  17. if(navigator.webkitGetGamepads()[0] !== undefined)
  18. Module['removeRunDependency']("gamepad");
  19. else
  20. setTimeout(timeout, 100);
  21. }
  22. setTimeout(timeout, 100);
  23. }
  24. });