uph_loadingBars.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //Get your HEX colours at http://www.colorpicker.com
  2. var colourBackground = "#2a2a2a"; //This is your base colour
  3. var colourText = shadeColor('#3796E3',70); //This is calculated from your base colour (but can be a custom HEX)
  4. var colourLoadingBack = "#ffffff";// shadeColor('#3796E3',-10); //This is calculated from your base colour (but can be a custom HEX)
  5. var colourLoadingFront = "#d40700"; //shadeColor('#3796E3',-10); //This is calculated from your base colour (but can be a custom HEX)
  6. //Create an image to be drawn
  7. var loadingBarImage = new Image();
  8. loadingBarImage.src = 'html5game/load.png';
  9. loadingBarImage.width = 250;
  10. loadingBarImage.height = 110;
  11. loadingBarImage.x_offset = -(loadingBarImage.width/2);
  12. loadingBarImage.y_offset = -(loadingBarImage.height/2);
  13. if (typeof loading_bar_smoother === 'undefined') {
  14. var loading_bar_smoother = 0;
  15. }
  16. // Full screen Loading Bar (WebGL OFF)
  17. function jchtml5_fullscreen_loading_bar(_graphics, _width, _height, _total, _current, _loadingscreen){
  18. _width = window.innerWidth;
  19. _height = window.innerHeight;
  20. _canvas = document.getElementById("canvas");
  21. if (_canvas.width !== _width || _canvas.height !== _height)
  22. {
  23. // Set the canvas size
  24. _canvas.width = _width;
  25. _canvas.height = _height;
  26. // Fill entire screen with colour
  27. _graphics.fillStyle = colourBackground;
  28. _graphics.fillRect(0, 0, _width, _height);
  29. }
  30. _graphics = _canvas.getContext("2d");
  31. // Fill entire screen with colour
  32. _graphics.fillStyle = colourBackground;
  33. _graphics.fillRect(0, 0, _width, _height);
  34. /*
  35. //Draw the loading text
  36. _graphics.fillStyle = colourText;
  37. _graphics.font = "20px Arial";
  38. _graphics.textAlign="center";
  39. _graphics.fillText(toString(fillW)."%",_width / 2,(_height / 2) - 30);
  40. */
  41. // Calculate loading bar position and size
  42. var barW = Math.round(_width / 4);
  43. var barH = Math.max(Math.round(_height / 40), 4);
  44. var barX = Math.round((_width - barW) / 2);
  45. var barY = Math.round((_height - barH) / 1.75);
  46. // Draw the loading bar (full)
  47. _graphics.fillStyle = colourLoadingBack;
  48. _graphics.fillRect(barX, barY, barW, barH);
  49. // Work out the completion status
  50. var fillW = Math.round((barW / _total) * _current);
  51. //Make the loading bar smooth
  52. if (loading_bar_smoother < fillW){
  53. loading_bar_smoother += 1;
  54. }
  55. // Draw the loading bar (current) if something has loaded
  56. if (_current !== 0){
  57. _graphics.fillStyle = colourLoadingFront;
  58. _graphics.fillRect(barX, barY, loading_bar_smoother, barH);
  59. }
  60. //Draw the image onto the loding bar
  61. _graphics.drawImage(loadingBarImage,_width/2+loadingBarImage.x_offset,_height/2.5+loadingBarImage.y_offset);
  62. }
  63. function shadeColor(color, percent) {
  64. var num = parseInt(color.slice(1),16), amt = Math.round(2.55 * percent), R = (num >> 16) + amt, G = (num >> 8 & 0x00FF) + amt, B = (num & 0x0000FF) + amt;
  65. return "#" + (0x1000000 + (R<255?R<1?0:R:255)*0x10000 + (G<255?G<1?0:G:255)*0x100 + (B<255?B<1?0:B:255)).toString(16).slice(1);
  66. }