Commits

Anonymous committed dc84d2b

wait for textures, sprites and camera authorization before starting game.

  • Participants
  • Parent commits 53b4aff

Comments (0)

Files changed (4)

     line-height: 375px;
     color: #fff9d6;
     font-weight:bold;
-    font-size: 134px;
+    font-size: 64px;
     text-align: center;
+    background: black;
 }
 
 .floating {
 </head>
 <body>
     <div id="game">
-        <div id="hud">loading...</div>
+        <div id="hud">...</div>
         <div class="canvasContainer">
             <canvas id="2space" width=480 height=360></canvas>
             <div class="overlay"></div>
     space3d.setObjectiveDelegate( objectiveHandler );
 
     var go = function() {
+        console.log("go.");
         hud.hide();
         space3d.onWarpHoleState( space2d.setWarpHoleState );
         space2d.onBallWarped( space3d.addBall );
         next();
     }
 
-    hud.setMessage("authorize camera.");
-    assets.onAllTexturesLoaded( function() { console.log("all textures loaded.") } );
-    assets.onAllSpritesLoaded( function() { console.log("all sprites loaded.") } );
-    video.videoCamera.waitForAuthorization( go );
+    var texturesLoaded = false;
+    var spritesLoaded = false;
+    var cameraAuthorized = false;
+
+    var goIfReady = function() {
+        if( texturesLoaded && spritesLoaded && cameraAuthorized ) {
+            go();
+        }
+    }
+
+    assets.onAllTexturesLoaded( function() {
+        texturesLoaded = true;
+        goIfReady();
+    });
+
+    assets.onAllSpritesLoaded( function() {
+        spritesLoaded = true;
+        goIfReady();
+    });
+    
+    hud.setMessage("please authorize camera.");
+    video.videoCamera.waitForAuthorization( function() {
+        cameraAuthorized = true;
+        goIfReady();
+    });
 });
 
     var hide = function() {
         var element = document.getElementById("hud");
-        element.style.visibility = 'hidden';
+        element.style.display = 'none';
     }
 
     var show = function() {
         var element = document.getElementById("hud");
-        element.style.visibility = 'visible';
+        element.style.display = 'block';
     }
 
     return {
 
         var authorizedCallback = undefined;
         var waitForAuthorization = function(callback) {
+            authorizedCallback = callback;
             if(ready) {
                 callback();
             }
-            else {
-                authorizedCallback = callback;
-            }
         }
 
         var onGetUserMediaError = function(error) {