This is an oldschool fire effect which I did before in Flash8 and now I wanted to get more into AS3 and see how fast it is. I tested new stuff and did some experiments with the new functions. André posted that the ByteArray would be a bad solution for best framerates. But I think it depends on what you are doing and how.
On my computer the setPixel is slower. So how to use a ByteArray? I would suggest – keeping the new GarbageCollection in mind – to create a buffer which you overwrite each frame. This is done by the following code:
[as]
private const buffer: ByteArray = new ByteArray();
private function onEnterFrame(): Void {
buffer.position = 0;
while ( … ) {
…
buffer.writeUnsignedInt( color );
}
}
[/as]
This is very easy. Remember that the ByteArray is a stream. That means everything you write to that stream will be appended to the end. If you set the position to 0 all the bytes will be overwritten. Drawing the buffer to a BitmapData object is also very simple. Just have a look.
[as]
buffer.position = 0;
bmp.setPixels( rect, buffer );
[/as]
If you do not set the position to 0 the setPixels call will result in a black picture. The setPixels method is explained here.
The whole fire effect is build using pixel-acces. The Flash8 version was 50x50px small. Now it is 100x100px … small. This is not very much and it is not very fast. What slows everything down are the function calls. André mentioned this also when he did his perspective texturemapping. Removing the one setPixel line resulted in a speed of 120fps. But of course it is only an Alpha. I hope they will fix such things and I am very enthusiastic!
3 Trackbacks
[...] 050.de/?p=35″ target=”_blank”> flashIRC – First Steps in Flash 8.5 and Flex (example) AS3 oldschool fire (source + example) AS3 oldschool tunnel (source + example) AS3 Bumbmaps (source [...]
ActionScript 3.0 站点集合
转自(http://bbs.javascript.com.cn/read.p…=1604&fpage=1)ActionScript 3.0 collection 68 sitesActionScript…
abc7 bingo game show…
brides deserve.precipitate captivation …