1、當(dāng)你移動(dòng)鼠標(biāo)時(shí),你可以看到蜘蛛絲會(huì)隨著鼠標(biāo)移動(dòng)和拉伸。
2、先說實(shí)現(xiàn)方法。
3、首先在閃存中構(gòu)建三個(gè)MCs。
(資料圖片僅供參考)
4、一個(gè)是spider_mc,畫個(gè)蜘蛛,體面點(diǎn)就行,呵呵!
5、一個(gè)是net_mc,一個(gè)蜘蛛網(wǎng),作為背景使用,但是用處不大。
6、最后一個(gè)是空MC,line_mc,用來畫線(蜘蛛絲)。
7、回到場景,建立三層。
8、最下面的叫網(wǎng),用來放背景網(wǎng),拉進(jìn)來。
9、中間層叫l(wèi)ine,用來放line_mc。拉入line_mc,并將此剪輯命名為line_mc。
10、最后一個(gè)當(dāng)然是spider_mc。
11、最關(guān)鍵的一步是建立一個(gè)動(dòng)作層,并編寫下面的代碼。
12、復(fù)制代碼
13、代碼如下:
14、speed=10;
15、spider_mc.onEnterFrame=function() {
16、dx=_root._xmouse-this._x;
17、dy=_root._ymouse-this._y;
18、p=Math.atan(dy/dx)*180/Math.PI;
19、rota=(dx0) ? (90+p):(270+p);
20、this._x +=dx/speed;
21、this._rotation=rota;
22、this._y +=dy/speed;
23、};
24、line_mc.onEnterFrame=function() {
25、this.clear();
26、this.moveTo(0,0);
27、this.lineStyle(1,0xffffff,100);
28、this.lineTo(_root.spider_mc ._x,_root.spider_mc ._ y);
29、};
30、最后,生成并完成swf。
本文到此結(jié)束,希望對(duì)大家有所幫助。