[url=http://www.bit-101.com/blog/?p=1040]原文在此[/url]
Kieth的blog。相当有趣。看来可以在这个blog上找到不少Flash 9/ActionScript 3的技巧。
原文的主旨在于对比是否使用double buffering对Flash中的绘制性能的影响。但阅读下面的评论会发现很有趣的结论:不用double buffering也未必会慢多少;可以使用“lock()”。
(摘自Kieth的blog)
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)