`
RednaxelaFX
  • 浏览: 3016230 次
  • 性别: Icon_minigender_1
  • 来自: 海外
社区版块
存档分类
最新评论

Flash中使用BitmapData来Double Buffering (转载链接)

阅读更多
原文在此
Kieth的blog。相当有趣。看来可以在这个blog上找到不少Flash 9/ActionScript 3的技巧。

原文的主旨在于对比是否使用double buffering对Flash中的绘制性能的影响。但阅读下面的评论会发现很有趣的结论:不用double buffering也未必会慢多少;可以使用“lock()”。

package {
    import flash.display.Sprite;
    import flash.utils.getTimer;
    import flash.display.Bitmap;
    import flash.display.BitmapData;

    public class BlitTest extends Sprite
    {
        public function BlitTest()
        {
            var bmp1:BitmapData = new BitmapData(500, 500, true, 0);
            var bmp2:BitmapData = new BitmapData(500, 500, true, 0);
            var bmp3:BitmapData = new BitmapData(500, 500, true, 0);
            var holder1:Bitmap = new Bitmap(bmp1);
            addChild(holder1);
            var holder2:Bitmap = new Bitmap(bmp2);

            var start:int
            var i:uint;

            start = getTimer();
            bmp1.lock();             // LOCK BITMAP
            holder1.visible = false; // AND SET TO INVISIBLE!
            for(i = 0; i <1000000; i++)
            {
                bmp1.setPixel(
                    Math.random() * 500,
                    Math.random() * 500,
                    Math.random() * 0xffffff);
            }
            bmp1.unlock();          // UNLOCK
            holder1.visible = true; // SET TO VISIBLE
            trace(getTimer() - start);


            start = getTimer();
            for(i = 0; i <1000000; i++)
            {
                bmp2.setPixel(
                    Math.random() * 500,
                    Math.random() * 500,
                    Math.random() * 0xffffff);
            }
            trace(getTimer() - start);

            start = getTimer();
            for(i = 0; i <1000000; i++)
            {
                bmp3.setPixel(
                    Math.random() * 500,
                    Math.random() * 500,
                    Math.random() * 0xffffff);
            }
            trace(getTimer() - start);
        }
    }
}

(摘自Kieth的blog)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics