Commits

abrie  committed 53b4aff

refactor: use a helper method to initialize texture loading

  • Participants
  • Parent commits 4d01df8

Comments (0)

Files changed (1)

         incorrect: {url:'xmark.png'},
     };
 
-    var allTexturesLoaded = false;
-    var notifyAllTexturesLoaded = undefined;
-
     var loadTexture = function(name, url) {
         THREE.ImageUtils.loadTexture(
             url,
             {},
             function(texture) {
                 textures[name].data = texture;
-                checkReady();
+                areAllTexturesReady();
             },
             function(texture) {
                 console.log("error loading texture.",texture);
         );
     }
 
-    var checkReady = function() {
+    var allTexturesLoaded = false;
+    var notifyAllTexturesLoaded = undefined;
+    var areAllTexturesReady = function() {
         for(var entry in textures) {
             if( !textures[entry].data ) {
                 return false;
         }
 
         allTexturesLoaded = true;
+
         if( notifyAllTexturesLoaded ) {
             notifyAllTexturesLoaded();
         }
+
+        return true;
     }
 
-    for(var entry in textures) {
-        loadTexture( entry, textures[entry].url );
+    var loadAllTextures = function() {
+        for(var entry in textures) {
+            loadTexture( entry, textures[entry].url );
+        }
     }
 
+    loadAllTextures();
+
     return {
         onAllTexturesLoaded: function(delegate) {
             notifyAllTexturesLoaded = delegate;