Commits

drk  committed 91a922b

- only add the .tick() of Maps once the levels are all loaded

  • Participants
  • Parent commits 21bd621

Comments (0)

Files changed (2)

 var level;
 var filePath;
 
-for (var i = 0 ; i < NUMBER_OF_LEVELS ; i++)
+    // load all but the last one
+for (var i = 0 ; i < NUMBER_OF_LEVELS - 1 ; i++)
     {
     filePath = 'maps/level' + i + '.json';
    
         });
     }
 
+    
+    // load the last one separately to add to the Ticker once everything is loaded
+filePath = 'maps/level' + i + '.json';
 
-
+$.ajax({
+    url: filePath, 
+    dataType: 'json',
+    beforeSend: function(xhr)
+        {
+        if (xhr.overrideMimeType)
+            {
+            xhr.overrideMimeType("application/json");
+            }
+        },
+    success: function(data)
+        {
+        LEVELS.push( data );
+        
+        Ticker.addListener( Maps.tick );
+        }
+    });
 }
 
 
 
 
 Maps.tick = function()
-{
+{  
 COUNT_TICKS++;
 
 var currentLevel = LEVELS[ CURRENT_LEVEL ];

File js/start_game.js

 initGame();
 
 Maps();
-
-Ticker.addListener( Maps.tick );
 }