comparison nodejs/animate.js @ 854:eff2f580b536 abs_n_rel_center

Use accessor to return bbox values
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 20 Sep 2010 22:43:43 +0800
parents 3c48a77b75d3
children 88f4916a0691
comparison
equal deleted inserted replaced
853:13e0953c3fb3 854:eff2f580b536
9 var ffs = 12; 9 var ffs = 12;
10 var frame_interval = 1000 / ffs; 10 var frame_interval = 1000 / ffs;
11 11
12 function linear_draw() { 12 function linear_draw() {
13 var percent; 13 var percent;
14 var x, y;
14 15
15 percent = (Date.now() - this._start_tm) / this.duration; 16 percent = (Date.now() - this._start_tm) / this.duration;
16 if(percent >= 1) { 17 if(percent >= 1) {
17 percent = 1; 18 percent = 1;
18 if (this.obj.timer) { 19 if (this.obj.timer) {
19 this.obj.timer.stop(); 20 this.obj.timer.stop();
20 delete this.obj.timer; 21 delete this.obj.timer;
21 } 22 }
22 } 23 }
23 this.obj.x = (this.targetx-this.startposx)*percent+this.startposx; 24 x = (this.targetx-this.startposx)*percent+this.startposx;
24 this.obj.y = (this.targety-this.startposy)*percent+this.startposy; 25 y = (this.targety-this.startposy)*percent+this.startposy;
26 this.obj.center.move(x, y);
25 this.app.refresh(); 27 this.app.refresh();
26 } 28 }
27 29
28 function linear_draw_start() { 30 function linear_draw_start() {
29 var obj = this.obj; 31 var obj = this.obj;
39 function linear(app,obj,shiftx,shifty,duration) { 41 function linear(app,obj,shiftx,shifty,duration) {
40 obj.animated_linear = this; 42 obj.animated_linear = this;
41 this.app = app; 43 this.app = app;
42 this.obj = obj; 44 this.obj = obj;
43 this.end = 0; 45 this.end = 0;
44 this.targetx = shiftx + obj.x; 46 this.targetx = shiftx + obj.center.x;
45 this.targety = shifty + obj.y; 47 this.targety = shifty + obj.center.y;
46 this.startposx = obj.x; 48 this.startposx = obj.center.x;
47 this.startposy = obj.y; 49 this.startposy = obj.center.y;
48 this.duration = duration*1000; 50 this.duration = duration*1000;
49 } 51 }
50 52
51 exports.linear = linear; 53 exports.linear = linear;
52 linear.prototype.start = linear_draw_start; 54 linear.prototype.start = linear_draw_start;