Monkey2Game.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>${APPLICATION_NAME}</title>
  6. <link rel="stylesheet" href="style.css">
  7. </head>
  8. <body>
  9. <div class="header">
  10. <span>Resize canvas <input type="checkbox" id="resize"></span>&nbsp;&nbsp;
  11. <span>Hide mouse pointer <input type="checkbox" id="pointerLock"></span>&nbsp;&nbsp;
  12. <a class="button" onclick="Module.requestFullScreen(document.getElementById('pointerLock').checked,document.getElementById('resize').checked)">Fullscreen</a>
  13. </div>
  14. <div class="status">
  15. <span id="status"></span>
  16. </div>
  17. <div class="canvas">
  18. <div class="center">
  19. <canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
  20. </div>
  21. </div>
  22. <textarea id="output" rows="10"></textarea>
  23. <script type="text/javascript">
  24. var statusElement = document.getElementById('status');
  25. var Module = {
  26. preRun: [],
  27. postRun: [],
  28. print: (function() {
  29. var element = document.getElementById('output');
  30. if (element) element.value = ''; // clear browser cache
  31. return function(text) {
  32. if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
  33. // These replacements are necessary if you render to raw HTML
  34. //text = text.replace(/&/g, "&amp;");
  35. //text = text.replace(/</g, "&lt;");
  36. //text = text.replace(/>/g, "&gt;");
  37. //text = text.replace('\n', '<br>', 'g');
  38. console.log(text);
  39. if (element) {
  40. element.value += text + "\n";
  41. element.scrollTop = element.scrollHeight; // focus on bottom
  42. }
  43. };
  44. })(),
  45. printErr: function(text) {
  46. if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
  47. if (0) { // XXX disabled for safety typeof dump == 'function') {
  48. dump(text + '\n'); // fast, straight to the real console
  49. } else {
  50. console.error(text);
  51. }
  52. },
  53. canvas: (function() {
  54. var canvas = document.getElementById('canvas');
  55. // As a default initial behavior, pop up an alert when webgl context is lost. To make your
  56. // application robust, you may want to override this behavior before shipping!
  57. // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
  58. canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
  59. return canvas;
  60. })(),
  61. setStatus: function(text) {
  62. if( !statusElement ) return;
  63. if( text ){
  64. statusElement.innerHTML=text;
  65. statusElement.hidden=false;
  66. }else{
  67. statusElement.hidden=true;
  68. }
  69. }
  70. };
  71. Module.setStatus( 'Downloading...' );
  72. window.onerror=function(event) {
  73. // TODO: do not warn on ok events like simulating an infinite loop or exitStatus
  74. Module.setStatus('Exception thrown, see JavaScript console');
  75. Module.setStatus = function(text) {
  76. if (text) Module.printErr('[post-exception status] ' + text);
  77. };
  78. };
  79. var xhr=new XMLHttpRequest();
  80. xhr.open( 'GET','${APPLICATION_NAME}.wasm',true );
  81. xhr.responseType='arraybuffer';
  82. xhr.onload=function(){
  83. Module.wasmBinary=xhr.response;
  84. var script=document.createElement( 'script' );
  85. script.src='${APPLICATION_NAME}.js';
  86. document.body.appendChild(script);
  87. };
  88. xhr.send( null );
  89. </script>
  90. </body>
  91. </html>