折线运动效果:
新建一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;