changeset 1426:5487aaf6f863

Change the algorithm to determine the gap between frames so that the go back can be calculated correctly.
author wycc
date Sat, 09 Apr 2011 04:08:02 +0800
parents 13e126941bdd
children 5b69baa49a8b
files nodejs/mbapp.js
diffstat 1 files changed, 6 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/mbapp.js	Sat Apr 09 03:41:03 2011 +0800
+++ b/nodejs/mbapp.js	Sat Apr 09 04:08:02 2011 +0800
@@ -124,7 +124,7 @@
     this.keymap={};
     this.onKeyPress = null;
     this.svg = new svg.loadSVG(this.mb_rt,this.mb_rt.root,null);
-    this.frame_interval = 1000/30; // 12 frame per second
+    this.frame_interval = 1000/12; // 12 frame per second
     this.timer = null;
     this._time = Date.now();
     this._componentmanager = new component.ComponentManager(this);
@@ -386,20 +386,17 @@
 	    if (nextframe < this.targetScene)
 	        nextframe = this.targetScene;
 	}
+        this.changeScene(nextframe);
 	if (nextframe != this.targetScene) {
-	    var timegap = (nextframe-this.startScene)*this.skipdir*this.frame_interval+this.starttime - Date.now();
-	    sys.puts("goto "+timegap);
-	    if (timegap <200) {
-	        timegap = 0;
-	    } else {
-	    }
+	    var timegap = this.frame_interval - (Date.now()-now);
+	    if (timegap < 0) timegap = 0;
+	    
             this.timer = setTimeout(function() {
    	        self.skipFrame()
-	    }, timegap);
+	    }, timegap );
 	} else {
 	    this.timer = null;
 	}
-        this.changeScene(nextframe);
 	now = Date.now();
 	this.ts("goto end");
     }