annotate nodejs/animate.js @ 728:a843f147c995

Add Y coordiante in the linear animation.
author wycc
date Tue, 17 Aug 2010 08:31:24 +0800
parents 468cd504800c
children d11b0900f03c
rev   line source
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
1 var sys=require("sys");
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
2
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
3 function linear_draw() {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
4 if (this.end == 1) return;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
5 var percent = (Date.now() - this.starttime)/this.duration;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
6 if (percent > 1) percent = 1;
728
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
7 this.obj[2] = (this.targetx-this.startposx)*percent+this.startposx;
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
8 this.obj[5] = (this.targety-this.startposy)*percent+this.startposy;
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
9 this.app.refresh();
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
10 var self = this;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
11 if (percent < 1) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
12 this.obj.timer=setTimeout(function() { self.draw();}, 20);
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
13 return;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
14 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
15 this.app.refresh();
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
16 this.obj.animated_linear = null;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
17 }
728
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
18 function linear(app,obj,targetx,targety,duration) {
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
19 try {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
20 if (obj.animated_linear) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
21 obj[5] = obj.animated_linear.target;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
22 obj.animated_linear.end = 1;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
23 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
24 } catch(e) {
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
25
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
26 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
27 obj.animated_linear = this;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
28 this.app = app;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
29 this.obj = obj;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
30 this.end = 0;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
31 this.starttime = Date.now();
728
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
32 this.startposx = obj[2];
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
33 this.startposy = obj[5];
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
34 this.targetx = targetx;
a843f147c995 Add Y coordiante in the linear animation.
wycc
parents: 727
diff changeset
35 this.targety = targety;
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
36 this.duration = duration*1000;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
37 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
38
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
39
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
40 exports.linear = linear;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
41 linear.prototype.start = linear_draw;
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
42 linear.prototype.draw = linear_draw;