用Flash Actionscript简单制作可以任意拖动的四边形,是制作
游戏的一个基础
程序。
5 g6 z( c& ~4 u0 `
打开Flash,首先将属性改为30fps然后新建立一个组建laser,设置效果如下。
1 k d" {# G( R3 Z
然后回到主场景,在第一帧内输入Action。
5 Z4 V. Q$ Y, {+ Q
laser_nodes = 4;
+ r/ o ?) [6 }$ {
for (x=1; x<=laser_nodes; x++) {
( ^3 d5 F2 K7 k- I! ~+ b node = _root.attachMovie("laser", "laser_"+x, x, {_x:Math.random()*460+20, _y:Math.random()*310+20});
2 Q3 H* {9 R) D5 n! z( C5 N
node.onPress = function() {
8 \ I: y$ C: Z
startDrag(this);
' Y1 @7 t0 t; ^
};
4 m- q y$ b. X, h& _9 a, {
node.onRelease = function() {
% Z& ?( o `, P6 s0 P7 t" ] stopDrag();
& @, _$ b- S! C/ f! ?3 E) @1 B };
! c; g1 v' v& h9 R/ ?}
0 o8 ~+ B1 o# \6 @6 M9 W6 D
_root.createEmptyMovieClip("ray", _root.getNextHighestDepth());
& _6 M$ G5 s6 {! @& D
ray.onEnterFrame = function() {
; l- |9 Y* K, B! j- x6 V( y$ m1 o this.clear();
! n( Y& I) q# V- M8 ~
this.lineStyle(3, 0xff0000);
! x, S8 ^ H2 G! s0 z6 b this.moveTo(_root.laser_1._x, _root.laser_1._y);
9 f, O4 ?4 k- X1 Z) y6 p
for (x=2; x<=laser_nodes; x++) {
6 H4 f! ?9 c/ Z1 C* m6 W
this.lineTo(_root["laser_"+x]._x, _root["laser_"+x]._y);
9 A* g' a. {% Q+ c. L
}
9 \; @/ ?# P! T( P. H" M8 @
this.lineTo(_root.laser_1._x, _root.laser_1._y);
. H) i: C# B2 s' m$ ~( `' S};
% M& e2 S6 Y p: r7 g你可以修改上面的参数,比如laser_nodes = 其它数,就可以看到其它效果了!
3 Q! V1 i7 X8 w* y* F
最终演示效果。
, A& N' I4 u r; J3 r$ l
点击这里下载源文件
【