Commits

Anonymous committed b52a6ec

allow configurable events to be scheduled

Comments (0)

Files changed (1)

 
 function(createjs, video, display3d, space3d, display2d, space2d, editor2d, levels) {
 
+    var scheduledEvent = {
+        frames: 0,
+        invoke: undefined,
+    }
+
+    var scheduleEvent = function(frames, method) {
+        scheduledEvent.frames = frames;
+        scheduledEvent.invoke = method;
+    }
+
     var restart = function() {
         var level = JSON.parse(currentLevelData);
         space2d.loadWorld(level);
     var currentLevelNumber = -1;
     var next = function() {
         currentLevelNumber++;
-        load( levels.get(currentLevelNumber) );
+        var nextLevelData = levels.get(currentLevelNumber);
+        if( nextLevelData ) {
+            load( nextLevelData );
+        }
+        else {
+            console.log("no more levels.");
+        }
     }
 
     var previous = function() {
     }
 
     var objectiveHandler = function(success) {
-        console.log("objective success?:",success);
         if( success ) {
-            next();
+            scheduleEvent( 3*30, next );
         }
         else {
-            restart();
+            scheduleEvent( 3*30, restart );
         }
     }
 
         function tick(params) {
             update(1/params.delta);
             render();
+            if( scheduledEvent.frames > 0 ) {
+                if(--scheduledEvent.frames === 0) {
+                    scheduledEvent.invoke();
+                }
+            }
         }
 
         createjs.Ticker.useRAF = true;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.