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

[url=http://www.bit-101.com/blog/?p=1040]原文在此[/url]
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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值