2013-02-21 33 views
1

我試圖讓單個像素閃爍1/60秒,然後在2秒的時間內離開,直到1280x720屏幕上的每個像素閃爍白色。 2秒後,屏幕再次全黑,持續3秒左右,然後再循環。隨機像素閃爍1/60秒的白色

我解決它的方式是使用這個fla另一個stackoverflow用戶想出了,我修改了使用電影剪輯。問題是無法獲得921600個影片剪輯隨機啓動。它變得非常沉重和緩慢。看附加文件,與

無論如何!我確信有這樣一個超級聰明的方式。我是新手。感謝您的任何幫助或建議。

FLA(CS5) https://mega.co.nz/#!ERRFiJBJ!VYSaH164BcjD9QIiSdpk8WxFp68dYDC0vWzKySC8rg0

SWF https://mega.co.nz/#!kBoxmJCR!Mx7sHX94-9ch15dKdT8knHRRKRljytZXdOBK-2P-TLQ

最好, 羅林

對於我連接上述FLA的原始設計看到馬哈茂德·阿卜杜勒EL-解決方案Fattah在這個鏈接。 Random Start Times for Move Clips

+0

奇怪的網站,它不接受我的FF13爲「合格瀏覽器」,和NO,我不希望更新爲FF只有鐘聲和口哨。 ...實際上,每個單點的921600 MC都是巨大的矯枉過正,使用一個BitmapData(使用位圖封裝)並使用'setPixel32()'來更改它的顏色。 – Vesper 2013-02-21 05:17:23

+0

@Vesper這是在一個保管箱鏈接。我不認爲這個文件是非常有用的,除了看看它應該是什麼樣子。我知道我得到的是超級笨重的瘋狂矯枉過正,但是我不知道如何使用這個位圖包裝器。但是,謝謝你的方向。 https://dl.dropbox.com/u/753249/exposure7_2.fla https://dl.dropbox.com/u/753249/exposure7_2.swf – Rollin 2013-02-21 05:22:07

+1

首先看一下BitmapData類:http:// help。 adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html – mitim 2013-02-21 05:39:26

回答

2

好了,最簡單的方法是這樣的:

static const WIDTH:int=1280; 
static const HEIGHT:int=720; 
static const WH:int=WIDTH*HEIGHT; 
static const FRAMES:int=120; // 2 seconds * 60 frames. Adjust as needed 
static var VF:Vector.<int>; // primary randomizer 
static var BD:BitmapData; // displayed object 
static var curFrame:int; // current frame 
static var BDRect:Rectangle; 
function init():void { 
    // does various inits 
    if (!VF) VF=new Vector.<int>(WH,true); // fixed length to optimize memory usage and performance 
    if (!BD) BD=new BitmapData(WIDTH,HEIGHT,false,0); // non-transparent bitmap 
    BDRect=BD.rect; 
    BD.fillRect(BDRect,0); // for transparent BD, fill with 0xff000000 
    curFrame=-1; 
    for (var i:int=0;i<WH;i++) VF[i]=Math.floor(Math.random()*FRAMES); // which frame will have the corresponding pixel lit white 
} 
function onEnterFrame(e:Event):void { 
    curFrame++; 
    BD.lock(); 
    BD.fillRect(BDRect,0); 
    if ((curFrame>=0)&&(curFrame<FRAMES)) { 
     // we have a blinking frame 
     var cw:int=0; 
     var ch:int=0; 
     for (var i:int=0;i<WH;i++) { 
      if (VF[i]==curFrame) BD.setPixel(cw,ch,0xffffff); 
      cw++; // next column. These are to cache, not calculate 
      if (cw==WIDTH) { cw=0; ch++; } // next row 
     } 
    } else if (curFrame>FRAMES+20) { 
     // allow the SWF a brief black period. If not needed, check for >=FRAMES 
     init(); 
    } 
    BD.unlock(); 
} 
function Main() { 
    init(); 
    addChild(new Bitmap(BD)); 
    addEventListener(Event.ENTER_FRAME,onEnterFrame); 
} 
+0

嘿。我很愚蠢,實際上不知道如何使用你寫的代碼。它看起來是有道理的,如果我能使它成功的話,這些評論看起來像是有用的。 我把它放在空白的關鍵幀?我是否需要導入單個像素圖片或其他內容?對不起,我完全不熟悉這個東西。 – Rollin 2013-02-22 05:26:49

+0

那麼,BitmapData已經由像素組成。這個代碼可以放在類或關鍵幀中,如果是keyfrawe,你必須調用Main()或者刪除Main函數的Main函數,執行一次。最好將這段代碼放入一個擴展'Sprite'的類中,這樣'Main()'將成爲它的構造函數(爲此重命名函數),並調用addChild(new MyBlinkingStuff()); – Vesper 2013-02-22 08:20:30