// be sure to set what orientation the game prefers here landscape_preferred = false; landscape = landscape_preferred; // load the orientation image once var rotategfx= new Image(); rotategfx.src = "rotategfx.png"; rotatewidth = 480; rotateheight = 320; // load the loading bar image once //var loadbar0 = new Image(); //loadbar0.src = "loadbar0.png"; var loadbar1 = new Image(); loadbar1.src = "loadbar1.png"; var barwidth = 175; var barheight = 48; loadcanvas = null; c_graphics = null; function init() { loadcanvas = document.getElementById('loading_screen'); if(loadcanvas != null) { c_graphics = loadcanvas.getContext("2d"); loadcanvas.width = window.innerWidth; loadcanvas.height = window.innerHeight; c_width = loadcanvas.width; c_height = loadcanvas.height; //console.log(String(loadcanvas.width)+" "+String(loadcanvas.height)); //alert(String(loadcanvas.width)+" "+String(loadcanvas.height)); } } init(); function ios_remove_addressbar() { // Is this an iPad, iPhone or iPod? If so then scroll if(( navigator.userAgent.indexOf("iPhone")!=-1 ) || ( navigator.userAgent.indexOf("iPad")!=-1 ) || ( navigator.userAgent.indexOf("iPod")!=-1 )) { window.scrollTo(0, 0); } return 0; } function RenderLoadingBar_Standard(_graphics, _width,_height, _total, _current, _loadingscreen) { { if(loadcanvas == null) { init(); } ios_remove_addressbar(); var widthmult = c_width / _width; var heightmult = c_height / _height; var x = (_width - barwidth) / 2; // center the loading bar var y = 10 + (_height - barheight) * 0.6; // and the move it down fro the text a little var w = (barwidth / _total) * _current; // Clear screen c_graphics.fillStyle = "rgba(21,21,21,255)"; c_graphics.fillRect(0, 0, c_width, c_height); // draw custom load bar here // stretch BG to entire canvas c_graphics.drawImage(_loadingscreen, 0, 0, c_width, c_height); // Only draw the bar once "something" has loaded in. if (_current != 0) { // Draw the dark gray bar //c_graphics.drawImage(loadbar0, 0, 0, barwidth, barheight, x*widthmult, y*heightmult, barwidth*widthmult, barheight*heightmult); // Now draw the loaded files bar over the top. c_graphics.drawImage(loadbar1, 0, 0, w, barheight, x*widthmult, y*heightmult, w*widthmult, barheight*heightmult); } if (landscape != landscape_preferred) { c_graphics.drawImage(rotategfx, 0, 0, rotatewidth, rotateheight, 0,0, c_width, c_height); } } } // additional rotation code function doOnOrientationChange() { init(); if (landscape_preferred == true) { switch(window.orientation) { case 0: //alert('portrait'); landscape = false; break; default: //alert('landscape'); landscape = true; break; } } else { switch(window.orientation) { case -90: case 90: //alert('landscape'); landscape = true; break; default: //alert('portrait'); landscape = false; break; } } } // listen to both resize and orientation change for // cross-platform goodness window.addEventListener('orientationchange', doOnOrientationChange); window.addEventListener('resize', doOnOrientationChange); // Initial execution if needed doOnOrientationChange();