天天看點

逐漸出現的馬賽克遮照 - allonkwok

首先在場景中導入一個圖檔 把它轉換為影片剪輯

把影片剪輯放在主場景第一針

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

首先在場景中導入一個圖檔 把它轉換為影片剪輯

把影片剪輯放在主場景第一針

在該影片剪輯上寫下如下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;//設定透明度

    }

}

好了現在可以導出看效果了

逐漸出現的馬賽克遮照 - allonkwok