flash cs6中想要實現一個點擊蒲公英,蒲公英種子就飛出去的效果,該怎么實現呢?鼠標事件和幀頻事件是FLASH制作游戲中經常用到的代碼,們結合這兩種代碼就可以實現鼠標點擊蒲公英飛出的效果,下面我們就來看看詳細的教程。
1、這里使用的是FLASH CS6。打開軟件,新建AS3文檔。
2、修改舞臺大小為1280x720
3、百度蒲公英矢量素材,找到游戲中需要用到背景和蒲公英。
4、將素材導入到FLASH舞臺中。蒲公英的種子放四個不同形態的。
5、畫一個圓形放到花盤那里,轉換為影片剪輯。注意注冊點的位置居中,并把影片剪輯中心對準花盤。
6、設置實例名為container_mc
7、把花瓣轉換為影片剪輯,并把四個花瓣分到四個幀中,如下對齊,在第一幀加代碼:stop();
8、設置影片剪輯屬性如下圖所示:
9、在主時間軸加如下代碼:
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、運行后就可以看到效果了,當花瓣沒有后,會自動再添加新的。
以上就是flash制作點擊蒲公英飛出的效果的教程,希望大家喜歡,請繼續關注武林網。
相關推薦:
flash怎么制作文字飛入的動畫?
flash怎么制作一個足球飛奔入門的動畫?
Flash怎么制作紙飛機環形飛行的動畫效果?
新聞熱點
疑難解答