Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
727:468cd504800c | 728:a843f147c995 |
---|---|
2 | 2 |
3 function linear_draw() { | 3 function linear_draw() { |
4 if (this.end == 1) return; | 4 if (this.end == 1) return; |
5 var percent = (Date.now() - this.starttime)/this.duration; | 5 var percent = (Date.now() - this.starttime)/this.duration; |
6 if (percent > 1) percent = 1; | 6 if (percent > 1) percent = 1; |
7 this.obj[5] = (this.target-this.startpos)*percent+this.startpos; | 7 this.obj[2] = (this.targetx-this.startposx)*percent+this.startposx; |
8 this.obj[5] = (this.targety-this.startposy)*percent+this.startposy; | |
8 this.app.refresh(); | 9 this.app.refresh(); |
9 var self = this; | 10 var self = this; |
10 if (percent < 1) { | 11 if (percent < 1) { |
11 this.obj.timer=setTimeout(function() { self.draw();}, 20); | 12 this.obj.timer=setTimeout(function() { self.draw();}, 20); |
12 return; | 13 return; |
13 } | 14 } |
14 this.app.refresh(); | 15 this.app.refresh(); |
15 this.obj.animated_linear = null; | 16 this.obj.animated_linear = null; |
16 } | 17 } |
17 function linear(app,obj,target,duration) { | 18 function linear(app,obj,targetx,targety,duration) { |
18 try { | 19 try { |
19 if (obj.animated_linear) { | 20 if (obj.animated_linear) { |
20 obj[5] = obj.animated_linear.target; | 21 obj[5] = obj.animated_linear.target; |
21 obj.animated_linear.end = 1; | 22 obj.animated_linear.end = 1; |
22 } | 23 } |
26 obj.animated_linear = this; | 27 obj.animated_linear = this; |
27 this.app = app; | 28 this.app = app; |
28 this.obj = obj; | 29 this.obj = obj; |
29 this.end = 0; | 30 this.end = 0; |
30 this.starttime = Date.now(); | 31 this.starttime = Date.now(); |
31 this.startpos = obj[5]; | 32 this.startposx = obj[2]; |
32 this.target = target; | 33 this.startposy = obj[5]; |
34 this.targetx = targetx; | |
35 this.targety = targety; | |
33 this.duration = duration*1000; | 36 this.duration = duration*1000; |
34 } | 37 } |
35 | 38 |
36 | 39 |
37 exports.linear = linear; | 40 exports.linear = linear; |