Mercurial > MadButterfly
annotate nodejs/animate.js @ 804:55875133fa60
Compare performance of setInterval() and setTimeout()
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 01 Sep 2010 16:23:43 +0800 |
parents | 210e4d24a3ba |
children | ae2faf140dc2 |
rev | line source |
---|---|
794 | 1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
2 // vim: sw=4:ts=8:sts=4:ai | |
727 | 3 var sys=require("sys"); |
4 | |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
5 /* |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
6 * This is configuration for animate module. For slower or speeder |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
7 * machines, ffs can be decreased or increased respective. |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
8 */ |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
9 var ffs = 20; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
10 var frame_interval = 1000 / ffs; |
804
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
11 var tm_flag = 1; |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
12 |
727 | 13 function linear_draw() { |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
14 var percent; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
15 |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
16 this.percent = this.percent + this.step; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
17 percent = this.percent; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
18 if (percent > 1) percent = 1; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
19 |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
20 this.c++; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
21 if(percent >= 1) { |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
22 this.obj.timer.stop(); |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
23 delete this.obj.timer; |
804
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
24 sys.puts(Date.now() - this._start_tm); |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
25 } |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
26 |
728 | 27 this.obj[2] = (this.targetx-this.startposx)*percent+this.startposx; |
28 this.obj[5] = (this.targety-this.startposy)*percent+this.startposy; | |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
29 this.app.refresh(); |
804
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
30 if(tm_flag) { |
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
31 var self = this; |
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
32 if(percent < 1) |
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
33 this.obj.timer = setTimeout(function() { self.draw(); }, frame_interval); |
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
34 } |
727 | 35 } |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
36 |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
37 function linear_draw_start() { |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
38 var obj = this.obj; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
39 var self = this; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
40 |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
41 if(obj.timer) |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
42 obj.timer.stop(); |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
43 |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
44 this.startposx = obj[2]; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
45 this.startposy = obj[5]; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
46 this.c = 0; |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
47 this.step = 1000 / (this.duration * ffs); |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
48 this.percent = 0; |
804
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
49 this._start_tm = Date.now(); |
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
50 if(tm_flag == 1) |
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
51 obj.timer = setTimeout(function() { self.draw(); }, frame_interval); |
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
52 else |
55875133fa60
Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents:
798
diff
changeset
|
53 obj.timer = setInterval(function() { self.draw(); }, frame_interval); |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
54 } |
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
55 |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
56 function linear(app,obj,shiftx,shifty,duration) { |
794 | 57 obj.animated_linear = this; |
58 this.app = app; | |
59 this.obj = obj; | |
60 this.end = 0; | |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
61 this.targetx = shiftx + obj[2]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
62 this.targety = shifty + obj[5]; |
794 | 63 this.duration = duration*1000; |
727 | 64 } |
65 | |
66 exports.linear = linear; | |
795
46a4cd4d382b
Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents:
794
diff
changeset
|
67 linear.prototype.start = linear_draw_start; |
727 | 68 linear.prototype.draw = linear_draw; |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
69 |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
70 /* ------------------------------------------------------------ */ |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
71 function rotate(app, obj, ang, duration) { |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
72 this._app = app; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
73 this._obj = obj; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
74 this._ang = ang; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
75 this._duration = duration; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
76 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
77 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
78 function rotate_start() { |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
79 var obj = this._obj; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
80 var self = this; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
81 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
82 this._step = 1 / (ffs * this._duration); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
83 this._percent = 0; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
84 this._start_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
85 obj.timer = setInterval(function() { self.draw(); }, frame_interval); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
86 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
87 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
88 function rotate_draw() { |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
89 var percent; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
90 var ang; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
91 var sv, cv; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
92 var obj = this._obj; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
93 var mtx, shift; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
94 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
95 this._percent = percent = this._percent + this._step; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
96 if(percent > 1) { |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
97 percent = 1; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
98 obj.timer.stop(); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
99 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
100 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
101 ang = percent * this._ang; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
102 sv = Math.sin(ang); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
103 cv = Math.cos(ang); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
104 mtx = [cv, -sv, 0, sv, cv, 0]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
105 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
106 shift = [1, 0, -obj.center_x, 0, 1, -obj.center_y]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
107 mtx = multiply(mtx, shift); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
108 shift = [1, 0, obj.center_x, 0, 1, obj.center_y]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
109 mtx = multiply(shift, mtx); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
110 mtx = multiply(mtx, this._start_mtx); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
111 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
112 obj[0] = mtx[0]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
113 obj[1] = mtx[1]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
114 obj[2] = mtx[2]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
115 obj[3] = mtx[3]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
116 obj[4] = mtx[4]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
117 obj[5] = mtx[5]; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
118 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
119 this._app.refresh(); |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
120 } |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
121 |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
122 rotate.prototype.start = rotate_start; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
123 rotate.prototype.draw = rotate_draw; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
124 exports.rotate = rotate; |
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
125 |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
126 function multiply(s,d) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
127 var m=[]; |
794 | 128 m[0] = s[0]*d[0]+s[1]*d[3]; |
129 m[1] = s[0]*d[1]+s[1]*d[4]; | |
130 m[2] = s[0]*d[2]+s[1]*d[5]+s[2]; | |
131 m[3] = s[3]*d[0]+s[4]*d[3]; | |
132 m[4] = s[3]*d[1]+s[4]*d[4]; | |
133 m[5] = s[3]*d[2]+s[4]*d[5]+s[5]; | |
798
210e4d24a3ba
Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents:
795
diff
changeset
|
134 return m; |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
135 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
136 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
137 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
138 function scale_draw() { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
139 if (this.end == 1) return; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
140 var percent = (Date.now() - this.starttime)/this.duration; |
794 | 141 if (percent > 1) percent = 1; |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
142 var sx = (this.targetx-this.startsx)*percent+this.startsx; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
143 var sy = (this.targety-this.startsy)*percent+this.startsy; |
794 | 144 var t=[sx,0,0,0,sy,0]; |
145 this.obj[0] = sx; | |
146 this.obj[4] = sy; | |
147 this.obj[2] = this.origin_offset_x - (sx-this.startsx)*this.obj.center.x; | |
148 this.obj[5] = this.origin_offset_y - (sy-this.startsy)*this.obj.center.y; | |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
149 |
794 | 150 this.app.refresh(); |
151 var self = this; | |
152 if (percent < 1) { | |
153 this.obj.timer=setTimeout(function() { self.draw();}, 20); | |
154 return; | |
155 } | |
156 this.app.refresh(); | |
157 this.obj.animated_scale = null; | |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
158 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
159 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
160 function scale(app,obj,targetx,targety, duration) { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
161 try { |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
162 if (obj.animated_scale) { |
794 | 163 //obj[0] = obj.animated_scale.targetx; |
164 //obj[4] = obj.animated_scale.targety; | |
165 //obj[2] = obj.animated_scale.final_offset_x; | |
166 //obj[5] = obj.aninated_scale.final_offset_y; | |
167 obj.animated_scale.end = 1; | |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
168 } |
794 | 169 } catch(e) { |
170 | |
171 } | |
172 obj.animated_scale = this; | |
173 this.app = app; | |
174 this.obj = obj; | |
175 this.end = 0; | |
176 this.starttime = Date.now(); | |
177 this.startsx = obj[0]; | |
178 this.startsy = obj[4]; | |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
179 this.targetx = targetx; |
794 | 180 this.targety = targety; |
181 this.duration = duration*1000; | |
182 this.origin_offset_x = obj[2]; | |
183 this.origin_offset_y = obj[5]; | |
184 this.final_offset_x = this.origin_offset_x-(targetx-this.startsx)*obj.center.x; | |
185 this.final_offset_y = this.origin_offset_y-(targety-this.startsy)*obj.center.y; | |
758
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
186 } |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
187 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
188 |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
189 exports.scale = scale; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
190 scale.prototype.start = scale_draw; |
d11b0900f03c
Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents:
728
diff
changeset
|
191 scale.prototype.draw = scale_draw; |
788
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
192 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
193 function holder(app, coord) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
194 var mtx = [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
195 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
196 this._mtx = mtx; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
197 this._coord = coord; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
198 this._app = app; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
199 } |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
200 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
201 holder.prototype = { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
202 go_center: function(o) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
203 var sx, sy; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
204 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
205 sx = o.center_x - this._coord.center_x; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
206 sy = o.center_y - this._coord.center_y; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
207 this.shift(sx, sy); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
208 }, |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
209 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
210 home: function() { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
211 this._coord[2] = this._mtx[2]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
212 this._coord[5] = this._mtx[5]; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
213 this._app.refresh(); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
214 }, |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
215 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
216 shift: function(sx, sy) { |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
217 this._coord[2] = this._mtx[2] + sx; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
218 this._coord[5] = this._mtx[5] + sy; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
219 this._app.refresh(); |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
220 } |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
221 }; |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
222 |
7ec13634c97d
Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents:
776
diff
changeset
|
223 exports.holder = holder; |