Mercurial > MadButterfly
changeset 844:3c48a77b75d3
USe obj.x and obj.y to implement the linear animation
author | wycc |
---|---|
date | Sun, 19 Sep 2010 11:36:42 +0800 |
parents | 2bcacd29d95f |
children | 2101a355acba |
files | nodejs/animate.js |
diffstat | 1 files changed, 13 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/animate.js Sun Sep 19 11:36:03 2010 +0800 +++ b/nodejs/animate.js Sun Sep 19 11:36:42 2010 +0800 @@ -6,7 +6,7 @@ * This is configuration for animate module. For slower or speeder * machines, ffs can be decreased or increased respective. */ -var ffs = 20; +var ffs = 12; var frame_interval = 1000 / ffs; function linear_draw() { @@ -15,13 +15,13 @@ percent = (Date.now() - this._start_tm) / this.duration; if(percent >= 1) { percent = 1; - - this.obj.timer.stop(); - delete this.obj.timer; + if (this.obj.timer) { + this.obj.timer.stop(); + delete this.obj.timer; + } } - - this.obj[2] = (this.targetx-this.startposx)*percent+this.startposx; - this.obj[5] = (this.targety-this.startposy)*percent+this.startposy; + this.obj.x = (this.targetx-this.startposx)*percent+this.startposx; + this.obj.y = (this.targety-this.startposy)*percent+this.startposy; this.app.refresh(); } @@ -32,8 +32,6 @@ if(obj.timer) obj.timer.stop(); - this.startposx = obj[2]; - this.startposy = obj[5]; this._start_tm = Date.now(); obj.timer = setInterval(function() { self.draw(); }, frame_interval); } @@ -43,8 +41,10 @@ this.app = app; this.obj = obj; this.end = 0; - this.targetx = shiftx + obj[2]; - this.targety = shifty + obj[5]; + this.targetx = shiftx + obj.x; + this.targety = shifty + obj.y; + this.startposx = obj.x; + this.startposy = obj.y; this.duration = duration*1000; } @@ -134,7 +134,7 @@ this.app.refresh(); var self = this; if (percent < 1) { - this.obj.timer=setTimeout(function() { self.draw();}, 20); + this.obj.timer=setTimeout(function() { self.draw();}, frame_interval); return; } this.app.refresh(); @@ -218,13 +218,12 @@ var percent = (Date.now() - this.starttime)/this.duration; if (percent > 1) percent = 1; var sx = (this.targetalpha-this.startalpha)*percent+this.startalpha; - sys.puts("opacity="+sx); this.obj.opacity=sx; this.app.refresh(); var self = this; if (percent < 1) { - this.obj.timer=setTimeout(function() { self.draw();}, 20); + this.obj.timer=setTimeout(function() { self.draw();}, frame_interval); return; } this.app.refresh();