Flash制作仿屏保的折线和曲线运动效果

王朝other·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

折线运动效果:

新建一MC元件,在MC的时间轴上写入下面的代码:

this._x = this._y = 0;

total = 5;

myColor = random(0xffffff);

speed = 5;

for (i = 0; i < total; i++) {

createEmptyMovieClip("mc" + i, i);

this["mc" + i]._y = random(Stage.height);

this["mc" + i]._x = random(Stage.width);

this["mc" + i].xsp = random(speed) + 5;

this["mc" + i].ysp = random(speed) + 5;

}

onEnterFrame = function () {

r = Math.floor(random(5));

g = Math.floor(random(10));

b = Math.floor(random(20));

//myColor += r << 32 + g << 16 + b;

//myColor &= 0xffffff;

for (i = 0; i < total; i++) {

with (this["mc" + i]) {

_x = _x + xsp;

_y = _y + ysp;

if (_x > Stage.width || _x < 0) {

xsp = -xsp;

myColor += r << 32 + g << 16 + b;

myColor &= 0xffffff;

}

if (_y > Stage.height || _y < 0) {

ysp = -ysp;

myColor += r << 32 + g << 16 + b;

myColor &= 0xffffff;

}

}

}

createEmptyMovieClip("xian", 100);

with (xian) {

lineStyle(2, myColor, 100);

start_pt_x = (mc0._x + this["mc" + (total - 1)]._x) / 2;

start_pt_y = (mc0._y + this["mc" + (total - 1)]._y) / 2;

moveTo(start_pt_x, start_pt_y);

for (i = 0; i < total - 1; i++) {

ctl_pt_x = this["mc" + i]._x;

ctl_pt_y = this["mc" + i]._y;

end_pt_x = (this["mc" + (i + 1)]._x + this["mc" + i]._x) / 2;

end_pt_y = (this["mc" + (i + 1)]._y + this["mc" + i]._y) / 2;

curveTo(ctl_pt_x, ctl_pt_y, end_pt_x, end_pt_y);

}

ctl_pt_x = this["mc" + (total - 1)]._x;

ctl_pt_y = this["mc" + (total - 1)]._y;

end_pt_x = (this["mc0"]._x + this["mc" + (total - 1)]._x) / 2;

end_pt_y = (this["mc0"]._y + this["mc" + (total - 1)]._y) / 2;

curveTo(ctl_pt_x, ctl_pt_y, end_pt_x, end_pt_y);

}

};

在主场景中拖入三个该元件,效果如下:

曲线运动效果:

绘制折线的代码如下:

this._x = this._y = 0;

total = 6;

myColor = random(0xffffff);

speed = 5;

for (i = 0; i < total; i++) {

createEmptyMovieClip("mc" + i, i);

this["mc" + i]._y = random(Stage.height);

this["mc" + i]._x = random(Stage.width);

this["mc" + i].xsp = random(speed) + 5;

this["mc" + i].ysp = random(speed) + 5;

}

onEnterFrame = function () {

r = Math.floor(random(5));

g = Math.floor(random(10));

b = Math.floor(random(20));

//myColor += r << 32 + g << 16 + b;

//myColor &= 0xffffff;

for (i = 0; i < total; i++) {

with (this["mc" + i]) {

_x = _x + xsp;

_y = _y + ysp;

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航