随机像素闪烁白色1/60秒

时间:2013-02-21 05:01:20

标签: actionscript-3 flash actionscript flash-cs5

我试图使单个像素闪烁1/60秒,然后在2秒的时间内消失,直到1280x720屏幕上的每个像素都闪烁白色。经过2秒后,屏幕再次全黑,持续3秒左右,然后再循环播放。

我解决它的方式是使用另一个stackoverflow用户提出的另一个和我修改它使用影片剪辑。问题是它无法使921600影片剪辑随机启动。它变得非常沉重和缓慢。请参阅与

一起使用的附件

反正!我确信有一种非常聪明的方法可以做到这一点。我是新手。感谢您提供任何帮助或建议。

fla(cs5) https://mega.co.nz/#!ERRFiJBJ!VYSaH164BcjD9QIiSdpk8WxFp68dYDC0vWzKySC8rg0

瑞士法郎 https://mega.co.nz/#!kBoxmJCR!Mx7sHX94-9ch15dKdT8knHRRKRljytZXdOBK-2P-TLQ

最好的, 罗林

对于上面链接的fla的原始设计,请参阅Mahmoud Abd El-Fattah在此链接上的解决方案。 Random Start Times for Move Clips

1 个答案:

答案 0 :(得分: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);
}
相关问题