逐漸出現的馬賽克遮照

首先在場景中導入一個圖片 把它轉換爲影片剪輯
把影片剪輯放在主場景第一針

在該影片剪輯上寫下如下AS

onClipEvent (load)//當影片剪輯出現在時間軸上時,執行大括號裏的語句 {
               numY = 56;
    numY = 70;;//定義圖象顯示的尺寸
                numPerFrame = 60//定義針速
    currSquare = 0;
    choices = new Array();
    for (i=0; i<numX*numY; i++) {
        choices.push(i);//定義一個新的數組  並不斷增加數組長度
    }
    _root.createEmptyMovieClip("mask", 0);//
    this.setMask(_root.mask);//創建一個影片剪輯 作爲遮照
    function drawSquare(x, y) {
        with (_root.mask) {
            moveTo(x, y);
            beginFill(0x000088);
            lineTo(x+10, y);
            lineTo(x+10, y+10);
            lineTo(x, y+10);
            endFill();//畫出這個遮照,  形狀爲10*10象素的方塊
        }
    }
}
onClipEvent (enterFrame)//影片剪輯針頻不斷觸發此動作 {
    if (currSquare<numX*numY) {
        for (i=0; i<numPerFrame; i++) {
            j = random(choices.length);
            t = choices[j];
            choices[j] = choices[choices.length-1];隨機選擇方快出現的時間
            choices.pop();//開始刪除數組choices中的元素
            x = t%numX;
            y = Math.floor(t/numX);//返回參數中表達式的下限值
            drawSquare(x*10, y*10);
        }
        currSquare += numPerFrame;
        this._alpha = currSquare/(numX*numY)*100;//設置透明度
    }
}

好了現在可以導出看效果了
 
發佈了8 篇原創文章 · 獲贊 0 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章