2021/9/11 15:25:38作者:佚名來源:網(wǎng)絡(luò)
今天我們來講解一個(gè)通過FLASH AS3來制作特酷的遮罩動(dòng)畫效果的教程,先看一下最終效果吧:
這里以FLASH CS4來講解,具體制作步驟如下:
步驟一、打開FLASH CS4,新建一個(gè)FLASH文檔,選擇AS3,然后按Ctrl+J進(jìn)行文檔屬性設(shè)置,把文檔的高度、寬度分別設(shè)置為550×314(這個(gè)大小與背景圖片大小相同),如圖:
步驟二、導(dǎo)入作為背景圖片,選中背景圖片,按下【F8】,轉(zhuǎn)為【影片剪輯】,名稱填寫【背景圖】,這個(gè)名稱你可以自己任意填寫名稱,點(diǎn)【確定】,如圖所示:
接著對(duì)這個(gè)有背景圖的圖層進(jìn)行鎖定,如圖:
步驟三、新建一個(gè)圖層,取個(gè)名稱遮罩層,然后橢圓工具畫一個(gè)禁止筆觸為50*50的圓,填充黑色(其實(shí)這里可以填充任何一種顏色),然后按F8,把這個(gè)圓轉(zhuǎn)為影片剪輯,名稱設(shè)為mask,如圖所示:
步驟四、刪除舞臺(tái)中的這個(gè)圓,把該圖層改名為AS。
步驟五、新建ActionScript文件,編寫一個(gè)外部的MyMask.as文件。在編譯器中輸入代碼如下:
package { import flash.display.MovieClip; public class MyMask extends MovieClip { //Mask's x and y speed public var speedX:Number; public var speedY:Number; //Set the given scale for this mask, when we create a new //mask object public function MyMask(scale:Number) { this.scaleX = scale; this.scaleY = scale; } } }
步驟六、轉(zhuǎn)到flash中的as層,輸入如下as代碼:
//We use an array to hold all our masks. //(Except the mask that follows our cursor) var masks:Array = new Array(); //We add all of the masks to a container var maskContainer:Sprite = new Sprite(); //Set the maskContainer to be the image's mask backgroundImage.mask=maskContainer; //Add the container on the stage addChild(maskContainer); //Create the mask which follows cursor movement (master mask) var masterMask:MyMask=new MyMask(1); //Set the master masks's coordinates to match cursor's coordinates masterMask.x=mouseX; masterMask.y=mouseY; //Add the master mask to a container maskContainer.addChild(masterMask); //Cache the image and container as bitmap, so we //can animate the alpha of the masks maskContainer.cacheAsBitmap=true; backgroundImage.cacheAsBitmap=true; //Create a timer that is called every 0.2 seconds var timer:Timer=new Timer(200,0); timer.addEventListener(TimerEvent.TIMER, timerEvent); timer.start(); //This function is called every 0.2 seconds. //We create a new mask in this function. function timerEvent(e:TimerEvent):void { //Calculate a random scale for the new mask (0 to 1.5) var scale:Number=Math.random()*1.5 + 0.5; //Create a new mask with random scale var newMask:MyMask=new MyMask(scale); //Set the position for the new mask newMask.x=mouseX; newMask.y=mouseY; //Assign a random x and y speed for the mask newMask.speedX=Math.random()*20-10; newMask.speedY=Math.random()*20-10; //Add the mask to the container maskContainer.addChild(newMask); //Add the mask to the array masks.push(newMask); } //We need ENTER_FRAME to animate the masks addEventListener(Event.ENTER_FRAME, enterFrameHandler); //This function is called in each frame function enterFrameHandler(e:Event):void { //Loop through the mask array for (var i:uint = 0; i < masks.length; i++) { //Save a mask to a local variable var myMask:MyMask = (MyMask)(masks[i]); //Update the x and y position myMask.x+=myMask.speedX; myMask.y+=myMask.speedY; //Increase the scale myMask.scaleX+=0.1; myMask.scaleY+=0.1; //Reduce the alpha myMask.alpha-=0.01; //If the alpha is below 0, remove the mask //from the container and from the array if (myMask.alpha<0) { masks.splice(i,1); maskContainer.removeChild(myMask); } } //Update the master mask position masterMask.x=mouseX; masterMask.y=mouseY; }
至此,整個(gè)用AS3制作的特酷的遮罩動(dòng)畫效果動(dòng)畫就制作完成了,你可以按Ctrl+Enter進(jìn)行測(cè)試。
感興趣的朋友可以直接下載flash源碼研究一下。
標(biāo)簽: as3 遮罩
相關(guān)文章
金山數(shù)據(jù)恢復(fù)大師官方版 v1.0.0.2
詳情南方測(cè)繪Cass10v10.1.6中文
詳情revit 2017
詳情KeyShot Pro 9中文(附安裝教程) v9.0.286
詳情網(wǎng)易新聞客戶端v105.3
詳情AIMP4v5.11.2421中文綠色美化版
詳情onekey一鍵還原v18.0.18.1008
詳情浩辰CAD2020綠色v20.0
詳情好圖網(wǎng)圖標(biāo)轉(zhuǎn)換工具v4.9.7
詳情Adobe indesign cs6
詳情aardiov35.0.0中文最新版
詳情Adobe Creative Cloud 2024簡體中文v5.3.0.48
詳情暴風(fēng)影音16 v9.04.1029去廣告精簡版
詳情ASP.NET Maker 2019(ASP.NET代碼生成工具)v12.0.4.0
詳情暴風(fēng)影音v5.92.0824.1111
詳情迅雷5穩(wěn)定版v5.8.14.706
詳情使命召喚17官方中文版 v1.0
詳情死亡之雨新的僵尸病毒中文v1.0綠色免安裝版
詳情輻射4v1.7.15.0整合版
詳情克莉2v1.0中文版
詳情冬日計(jì)劃v1.2中文版
詳情刺客信條英靈殿v1.0吾愛
詳情刺客信條英靈殿終極v1.0免安裝
詳情動(dòng)物森友會(huì)v1.10.0最新
詳情哈迪斯殺出地獄v1.37中文
詳情嗜血印中文豪華版v1.0豪華版 附游戲攻略秘籍
詳情城市戰(zhàn)斗v1.0中文
詳情尼爾人工生命v1.0steam免費(fèi)
詳情尼爾人工生命升級(jí)版v1.0PC
詳情層層恐懼2中文v1.0綠色免安裝版
詳情往日不再v1.0 steam
詳情往日不再v1.0pc
詳情小生活游戲內(nèi)置MOD版v2.0(57)安卓版
詳情使命召喚手游測(cè)試服最新版v1.9.41安卓版
詳情三國謀定天下官服v1.2.1安卓版
詳情熱血新手村高爆版v1.0.0安卓版
詳情我養(yǎng)你啊手機(jī)版v1.0.0安卓版
詳情看懂了就很恐怖的故事(細(xì)思極恐)中文版v1.0安卓版
詳情背包英雄中文手機(jī)版v1.1.1安卓版
詳情glow官方版v2.0.9安卓版
詳情三國大時(shí)代4霸王立志官方正版v1.9安卓版
詳情飛盧小說閱讀器手機(jī)版v7.0.7安卓版
詳情牛?;浾Z詞典軟件v20.4.4安卓版
詳情PrettyUp視頻美化瘦身軟件v2.3.0
詳情化學(xué)方程式app中文版v1.1.0.20安卓版
詳情地下城堡3魂之詩2024安卓最新版v1.2.3安卓版
詳情南方都市報(bào)v6.10.0安卓版
詳情阿修羅之眼正版v1.0.10安卓版
詳情