Guest User

Untitled

a guest
Jul 27th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // If our screen is smaller than 640px in width (that's CSS pixels), we scale the
  2. // internal resolution of the canvas by 2. This gives us a larger viewport and
  3. // also essentially enables retina resolution on the iPhone and other devices
  4. // with small screens.
  5. var scale = (window.innerWidth < 640) ? 2 : 0.5;
  6.  
  7.  
  8. // We want to run the game in "fullscreen", so let's use the window's size
  9. // directly as the canvas' style size.
  10. var canvas = document.getElementById('canvas');
  11. canvas.style.width = window.innerWidth + 'px';
  12. canvas.style.height = window.innerHeight + 'px';
  13.  
  14.  
  15. // Listen to the window's 'resize' event and set the canvas' size each time
  16. // it changes.
  17. window.addEventListener('resize', function(){
  18.     console.log("resize event fired");
  19.  
  20.     // If the game hasn't started yet, there's nothing to do here
  21.     if( !ig.system ) { return; }
  22.  
  23.     // Resize the canvas style and tell Impact to resize the canvas itself;
  24.     canvas.style.width = window.innerWidth + 'px';
  25.     canvas.style.height = window.innerHeight + 'px';
  26.  
  27.     console.log("canvas.style.width: " + canvas.style.width);
  28.     console.log("canvas.style.height: " + canvas.style.height);
  29.  
  30.     ig.system.resize( window.innerWidth * scale, window.innerHeight * scale );
  31.  
  32.     // Also repositon the touch buttons, if we have any
  33.     if( window.myTouchButtons ) {
  34.         window.myTouchButtons.align();
  35.     }
  36. }, false);
  37.  
  38.  
  39. // Finally, start the game into MyGame and use the ImpactSplashLoader plugin
  40. // as our loading screen
  41. var width = window.innerWidth * scale,
  42.     height = window.innerHeight * scale;
  43.  
  44. ig.main( '#canvas', Titlescreen, 60, width, height, 1, ig.ImpactSplashLoader );
Add Comment
Please, Sign In to add comment