November 28, 2007 at 5:05 pm
· Filed under Sandy3d, BitmapData, Performance, Papervision3d, AS3
I was making some experiments with Sandy3d and Papervision3d and I realized some tips to increase the performance.
Firstly, with Sandy3d 3.0, when you create a BitmapMaterial, the BitmapData that you used to create the Material, is cloned to create the BitmapMaterial.texture.
So, one think you can do is dispose the BitmapData that you used to create the Material after instantiating it and also, if you want to update your BitmapData use the BitmapMaterial.texture directly.
Something like this:
var bmpData:BitmapData =
new BitmapData
(100,
100,
true, 0×00000000
);
var bmpMaterial:BitmapMaterial =
new BitmapMaterial
(bmpData
);
bmpData.dispose();
bmpMaterial.texture.fillRect(new Rectangle(10,10,30,30), 0xffff0000);
This will not work with Papervision3d because it uses the same BitmapData instance (in my opinion, smarter).
Now for both, Sandy3d and Papervision3d.
As you make changes on your BitmapData, it’s updated on every poligon.
So, use the BitmapData.lock() and BitmapData.unlock() when you are redrawing your BitmapData texture.
var bmpData:BitmapData =
new BitmapData
(100,
100,
false, 0×00000000
);
var bmpMaterial:BitmapMaterial =
new BitmapMaterial
(bmpData
);
redrawBitmap();
…
function redrawBitmap(){
bmpData.lock();
bmpData.fillRect(bmpData.rect, 0×00000000);
bmpData.fillRect(new Rectangle(10,10,30,30), 0xffff0000);
var blurFilter:BlurFilter = new BlurFilter(16, 16, 3);
bmpData.applyFilter(bmpData, bmpData.rect, new Point(0,0), blurFilter);
bmpData.unlock();
}
Permalink
November 19, 2007 at 2:21 pm
· Filed under TextField, source, BitmapData, AS3
Actually, I didn’t show the source because I wanted to know how many people was reading it, and was interested about it… so let me reveal the little trick.
First, I create a TextField, selectable(obviously) and set the alpha to zero.
Than, create a BitmapData with the TextField size, and, just draw the TextField on BitmapData each time the selection changes.
When you draw the BitmapData, there is to ways to change the selection color, using the ColorTransform or PalleteMap methods.
After that, you just place the Bitmap behind the textField.
var color = 0xff0000;
var c = ColorUtils.
getRGB(color);
highlightBmpData.fillRect(highlightBmpData.rect, 0×00000000);
highlightBmpData.draw(textField);
highlightBmpData.colorTransform(highlightBmpData.rect, new ColorTransform(1, 1, 1, 1, c.r, c.g, c.b, 0));
One thing is that, using Color transform, you can change easily the smoothed fonts, and with PalleteMap is harder.
Just remember that the selection color is always black, so you need to change the black part of the BitmapData to any color you want.
Easy huh?
PS: weird thing is that some people couldn’t see the effect on Mac with Firefox… I didn’t try it yet, but I’ll try to find a way to make it work.
Permalink
November 15, 2007 at 2:36 pm
· Filed under TextField, AS3
Ever tried to change the textField selection color on Flash?
Here is it.
Click on the colored boxes and click and drag to select the text.
Permalink
November 9, 2007 at 10:57 pm
· Filed under Jobs
São Paulo/Brazil - based studio, Agencia Ginga is hiring Flash Developer.
Actually, they are looking for someone already living in São Paulo, and speaks Portuguese.
Anyway, take a look at the job descriptionVaga para Flash Developer, and apply for it if you think you are good enough.
Permalink
November 8, 2007 at 1:12 am
· Filed under Benchmark, Graphics, BitmapData, Performance, AS3
Firstly… sorry for my poor English…
Working on Recyou.jp, I had to use many BitmapDatas, and so, I had to work out some way to make it lighter.
One thing I realized is that using Graphics.beginBitmapFill besides BitmapData.draw its much faster.
I made the benchmarks, drawing 10000 bitmapDatas, one using BitmapData.draw, and other using Graphics.beginBitmapFill.
First the benchmark with BitmapData.draw (Clicking on the flash it will re-run the benchmark):
The code is something like this:
var genericBmp:BitmapData = new BitmapData(100,100, false, 0×000000);
var bmp:BitmapData = new BitmapData(100,100, false, 0×000000);
for(var i = 0; i < 10000; i++){
bmp.draw(genericBmp);
}
Now the benchmark with Graphics.beginBitmapFill (Clicking on the flash it will re-run the benchmark):
The code is something like this:
var genericBmp:BitmapData = new BitmapData(100,100, false, 0×000000);
var bmp:BitmapData = new BitmapData(100,100, false, 0×000000);
for(var i = 0; i < 10000; i++){
graphics.beginBitmapFill(genericBmp);
graphics.drawRect(0,0,100,100);
}
So, if you are trying to create some bitmap pattens or attaching a Bitmap child and redrawing it’s BitmapData, try using the Graphics.beginBitmapFill.
Permalink