flash制造水墨场景中千山鸟飞绝尾随鼠标翱翔的逼真场景动画

更新时间:15-11-03 10:40 热度:531
 

flash制造水墨场景中千山鸟飞绝的逼真场景动画

飞鸟尾随鼠标点击位置翱翔,在银幕中点击恣意位置,飞鸟会飞向此处。

效果:

环境素材,右键挑选图片另存为

15110310403320360794202 flash制造水墨场景中千山鸟飞绝尾随鼠标翱翔的逼真场景动画

制造步骤

1、新建戏台尺寸为650*258像素,帧速20fps的文档。

2、导入环境图象到库中。

3、在戏台第1帧放入库中的环境图象,右键挑选环境,改换为图形元件。

4、新建飞鸟影片儿剪接,在戏台中画出飞鸟翅膀摇摆的效果。

15110310403356268098202 flash制造水墨场景中千山鸟飞绝尾随鼠标翱翔的逼真场景动画

5、回到库中,右键挑选飞鸟影片儿剪接,挑选链接属性,标明符为bird,勾选actionscript

15110310403379692825801 flash制造水墨场景中千山鸟飞绝尾随鼠标翱翔的逼真场景动画

6、回到主场景,新建一层,输入以下代码:

复制代码

代码如下所述:

//飞鸟起初体积以及数目、散布位置
function drawtopoint()
{
for (i = 0; i < numbirds; i++)
{
bird = _root["bird" + i];
bird.vx = bird.vx + (_xmouse – bird._x) * bird.k * 100;
bird.vy = bird.vy + (_ymouse – bird._y) * bird.k * 100;
} // end of for
} // end of the function
damp = 9.500000e-001;
numbirds = 30;
for (i = 0; i < numbirds; i++)
{
bird = attachmovie(“bird”, “bird” + i, i);
bird._x = math.random() * 350 + 20;
bird._y = math.random() * 300 + 20;
bird.vx = math.random() * 10 – 5;
bird.vy = math.random() * 10 – 5;
bird.k = math.random() * 1.000000e-004 + 3.000000e-004;
bird.gotoandplay(math.round(math.random() * 20));
} // end of for
//鼠标尾随代码
onenterframe = function ()
{
var totx = 0;
var toty = 0;
for (i = 0; i < numbirds; i++)
{
bird = _root["bird" + i];
totx = totx + bird._x;
toty = toty + bird._y;
} // end of for
avgx = totx / numbirds;
avgy = toty / numbirds;
for (i = 0; i < numbirds; i++)
{
bird = _root["bird" + i];
bird.vx = bird.vx + (avgx – bird._x) * bird.k;
bird.vy = bird.vy + (avgy – bird._y) * bird.k;
bird.vx = bird.vx + (math.random() – 5.000000e-001);
bird.vy = bird.vy + (math.random() – 5.000000e-001);
bird.vx = bird.vx * damp;
bird.vy = bird.vy * damp;
targangle = math.atan2(bird.vy, bird.vx) * 180 / 3.141593e+000;
diff = targangle – bird._rotation;
if (diff < -180)
{
diff = diff + 360;
} // end if
if (diff > 180)
{
diff = diff – 360;
} // end if
bird._rotation = bird._rotation + diff * 2.000000e-001;
bird._x = bird._x + bird.vx;
bird._y = bird._y + bird.vy;
} // end of for
};

onmousedown = drawtopoint;

7、测试影片儿获得以下效果: