GameJs/gamejs

Toggle Display

z3t0 opened this issue · 4 comments

z3t0 commented

It would be great if we could choose to turn the display off.

/**
 * Create the master Canvas plane.
 * @ignore
 */
exports.init = function() {
   // create canvas element if not yet present
   var canvas = getCanvas();
   if (!canvas.getAttribute('tabindex')) {
      // to be focusable, tabindex must be set
      canvas.setAttribute("tabindex", 1);
      canvas.focus();
   }
   // remove loader if any;
   var $loader = document.getElementById(LOADER_ID);
   if ($loader) {
      $loader.style.display = "none";
   }
   var $displaySurface = document.getElementById(CANVAS_ID);
   if ($displaySurface) {
      $displaySurface.style.display = 'block';
   }
   // hook into resize
   window.addEventListener("resize", onResize, false);
   return;
};

After a lot of experimenting I found that to be the code to enable the display.
Check #89

z3t0 commented
function _readyResources() {
         if (getImageProgress() < 1 || getMixerProgress() < 1) {
            return window.setTimeout(_readyResources, 100);
         }
         // gamejs.display.init();
         gamejs.image.init();
         gamejs.audio.init();
         gamejs.event.init();
         gamejs.math.random.init();
         readyFn();
      }

A much cleaner approach 😄

EDIT: THIS DOES NOT WORK...

z3t0 commented

My initial fix is incomplete, there seems to be more going on here...

z3t0 commented

I will take a look further, but it would probably be a lot easier for the initial developers to simply have an option for display on/off

i'm not sure what you are trying to do and you seem to have moved the problem into other issues. i'm closing this one.