Mercurial > MadButterfly
changeset 1439:c028aa928cc8
Update the API so that we can refresh screen in frame based. This will improve the poerformance of the animation.
author | wycc |
---|---|
date | Mon, 11 Apr 2011 13:05:19 +0800 |
parents | d19f47691d5e |
children | e5b3d68d0b05 |
files | nodejs/animate.js |
diffstat | 1 files changed, 30 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/animate.js Mon Apr 11 13:03:25 2011 +0800 +++ b/nodejs/animate.js Mon Apr 11 13:05:19 2011 +0800 @@ -11,11 +11,9 @@ function shift_draw(percent) { var x, y; - x = (this.targetx - this.startposx) * percent + this.startposx; y = (this.targety - this.startposy) * percent + this.startposy; this.obj.center.move(x, y); - this._app.refresh(); } function shift(app,obj,shiftx,shifty) { @@ -120,6 +118,7 @@ } + bbox = obj.bbox; bbox.update(); obj.animated_scale = this; @@ -211,6 +210,9 @@ { var now = Date.now(); var i; + + //now = this.lasttime + 300; + //this.lasttime += 300; if (now >= this.end) { this.timer.stop(); @@ -223,7 +225,13 @@ if (now < this.startmove) return; var per = (now-this.startmove)/this.duration/1000; if (per > 1) per = 1; - this.action.draw(per); + try { + for(a in this.action) { + this.action[a].draw(per); + } + } catch(e) { + sys.puts(e); + } } function linear_start() @@ -231,9 +239,20 @@ var self = this; if (this.timer) this.timer.stop(); - this.timer = setInterval(function() { self.update();}, frame_interval); + this.timer = setInterval(function() { + var n = Date.now(); + try { + self.update(); + self._app.refresh(); + } catch(e) { + sys.puts("libnear: "+e); + } + + //while( Date.now() - n < 1000); + }, frame_interval); this.startmove = Date.now()+this.starttime*1000; this.end = this.startmove+this.duration*1000; + this.lasttime = this.startmove; } function linear_stop() { @@ -245,19 +264,21 @@ function linear_finish() { - this.action.draw(1); + for(a in this.action) + this.action[a].draw(1); if (this.callback_end) { this.callback_end(); this.callback_end=null; } } -function linear(action,start, duration) +function linear(app,action,start, duration) { this.action = action; this.duration = duration; this.starttime = start; this.callback_end = null; this.timer=null; + this._app =app; } function linear_callback(cb) @@ -344,12 +365,10 @@ } } -exports.run = function(actions,start,duration,cb) { +exports.run = function(app,actions,start,duration,cb) { var li; - for(a in actions) { - li = new linear(actions[a],start,duration); - li.start(); - } + li = new linear(app,actions,start,duration); + li.start(); li.callbackAtEnd(cb); } exports.runexp=function(actions,start,exp) {