flash cs6中想要實(shí)現(xiàn)一個(gè)點(diǎn)擊蒲公英,蒲公英種子就飛出去的效果,該怎么實(shí)現(xiàn)呢?鼠標(biāo)事件和幀頻事件是FLASH制作游戲中經(jīng)常用到的代碼,們結(jié)合這兩種代碼就可以實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊蒲公英飛出的效果,下面我們就來看看詳細(xì)的教程。
1、這里使用的是FLASH CS6。打開軟件,新建AS3文檔。
2、修改舞臺(tái)大小為1280x720
3、百度蒲公英矢量素材,找到游戲中需要用到背景和蒲公英。
4、將素材導(dǎo)入到FLASH舞臺(tái)中。蒲公英的種子放四個(gè)不同形態(tài)的。
5、畫一個(gè)圓形放到花盤那里,轉(zhuǎn)換為影片剪輯。注意注冊(cè)點(diǎn)的位置居中,并把影片剪輯中心對(duì)準(zhǔn)花盤。
6、設(shè)置實(shí)例名為container_mc
7、把花瓣轉(zhuǎn)換為影片剪輯,并把四個(gè)花瓣分到四個(gè)幀中,如下對(duì)齊,在第一幀加代碼:stop();
8、設(shè)置影片剪輯屬性如下圖所示:
9、在主時(shí)間軸加如下代碼:
import flash.events.MouseEvent;import flash.display.MovieClip;var flowerAry:Array=new Array();var count:int=100;var left_count:int=0;initFlower();function initFlower():void{while(container_mc.numChildren>0){container_mc.removeChildAt(0);}flowerAry=new Array();left_count=count;for(var i:int=0;i<count;i++){flowerAry.push(new FLOWER());flowerAry[i].rotation=360*Math.random();flowerAry[i].scaleX=flowerAry[i].scaleY=0.6+0.4*Math.random();var temp:int=int(100000*Math.random())%flowerAry[i].totalFrames+1;flowerAry[i].x=5-10*Math.random();flowerAry[i].y=5-10*Math.random();flowerAry[i].gotoAndStop(temp);container_mc.addChild(flowerAry[i]);flowerAry[i].isMove=false;flowerAry[i].spdx=5*Math.random();flowerAry[i].spdy=(-1)*(3+3*Math.random());flowerAry[i].addEventListener(MouseEvent.CLICK,StartMove);}}function StartMove(e:MouseEvent):void{var obj:MovieClip=e.currentTarget as MovieClip;if(obj.isMove==true){return;}obj.isMove=true;obj.addEventListener(Event.ENTER_FRAME,AutoMoveEvent);}function AutoMoveEvent(e:Event):void{var obj:Object=e.target;if(obj.rotation!=0){obj.rotation=obj.rotation*0.9;}if(obj.y>-400){obj.y+=obj.spdy;obj.x+=obj.spdx;}else{obj.removeEventListener(Event.ENTER_FRAME,AutoMoveEvent);left_count--;if(left_count==0){initFlower();}}}
10、運(yùn)行后就可以看到效果了,當(dāng)花瓣沒有后,會(huì)自動(dòng)再添加新的。
以上就是flash制作點(diǎn)擊蒲公英飛出的效果的教程,希望大家喜歡,請(qǐng)繼續(xù)關(guān)注武林網(wǎng)。
相關(guān)推薦:
flash怎么制作文字飛入的動(dòng)畫?
flash怎么制作一個(gè)足球飛奔入門的動(dòng)畫?
Flash怎么制作紙飛機(jī)環(huán)形飛行的動(dòng)畫效果?
新聞熱點(diǎn)
疑難解答
圖片精選