If you were not able to visit the Spark Europe or MAX (like me) you might have a look at fabchannel.com where you can watch the whole “Natural Born Filters” lecture by André Michelle.
I did not know about fabchannel before but this seems to be a great site. I am looking forward to the Bloc Party webcast :-)
Share This
Exploring Actionscript 3 and Flex 2 makes a lot of fun! I created this google application in about two hours and the result looks nice. I have got some sweet resize effect, a data grid and a lot of window and button stuff. I am in love with Flex 2 and AS3!
The application itself is doing the following: After the user enters something to search for a PHP script gets loaded. This serverside script is only used as a proxy. It does not turn the Google website into some nice XML. I am using Flash to parse all the results. And I have to say it is pretty fast. To give it some more sense I added some lines of code that request the PHP script ten times to get 100 (possible) results.
This simple experiment shows what the new functions of Flash can do and how easy it is. You could have done this in other Flash versions of course. It is only an experiment and some sort of tutorial.
You see how to use regular expressions, the DataGrid and of course an URLLoader. The whole sourcecode is very simple and easy to understand. Have a look!
Share This
Imagine you want to code a raycaster or any l33t oldschool effect. What you need is direct pixel-access (ok, not really for the raycaster).
Now there is the problem which method could be used. image.setPixel for every pixel or image.setPixels.
Now some people talk about using setPixel because it is faster. This is something I can not understand, because for me the ByteArray was everytime a little bit faster.
I searched for problems using the ByteArray and even in some cases it seemd to me that the setPixel method is faster.
About how I tested the speed: I used a simple oldschool plasma for the speed comparison and tried differend methods to fill the image and also to store the palette.
Do not store colors / data in a ByteArray
Yes. For a plasma you can create a color palette. I used a simple Array and a ByteArray.
All colors are precached so the only thing I tried to optimize was the real data.
In the first test I used a ByteArray with 3 bytes per color. When the color was extracted I had to do this:
[as]pos = ((plasma[ x ][ y ] + paletteShift) % 256) * 3;
s.setPixel( x, y, (palette[ pos ] < < 16) | (palette[ pos + 1 ] << 8) | palette[ pos + 2 ] );[/as]
Of course the data which is stored in the memory is n * 1 byte less but putting all the values together slows flash down.
Continue reading ‘Be carefull with ByteArray’
Share This
This time a pixelscroller in Actionscript3.
I hope you know Zelda from the good old SNES. Maybe you do not, but there are two worlds, the light- and the darkworld. As Link you are able to switch between these two worlds using a teleporter.
Now what about Flash and two worlds?
This is just a quick result of a bored evening but you can see what is possible. The world is 2048×2048 px large and has 128×128 tiles with a size of 16×16 px. This makes it easy to imagine what huge chunks of data Flash has to manage and I think the speed is ok. Of course the 640×480 px version could be faster.
I also made a test while working on the tile engine with a Mario-Level. The speed at 640×480 px was ok (!) so with Flash 8.5 you are able to build nice tile engines that run with a high framerate at 640×480 px.
Press your left mouse button to switch between both worlds.
By the way I found an old bug. I am not sure if it really is a bug but this is annoying since Flash5. You have two listeners. One for onKeyDown and one for onKeyUp. Now you have an array of boolean values which shows you if a key is pressed or not. Something like function onKeyDown( event: KeyboardEvent ): Void { isKeyDown[ event.keyCode ] = true; } and the same with false for onKeyUp. Now if you press two keys at the same time and you release one and then the other there won’t be any event for the second onKeyUp.
Share This
André Michelle released not just a very fast raycaster today but also made a very interesting post on the Flashforum. It is about the optimization of your AS3 code and I am in awe of his creative tests. The fastest method to fill an Array in AS2 was this one:
[as]var n: Number = 1000;
while ( –n > -1 )
array[ n ] = 0;[/as]
Now André just posted another method wich is a lot faster. The webcam with particles experiment moved from 25fps to 30fps.
This is what he posted and it describes the technique very well:
[as]var x: Number = 0;
while( x++ < 1000 )
{
// do something
}
var x: Number = 0;
while( x < 1000 )
{
x++;
// do something faster
}
// or inside conditions
if( ( z = iz * 100 ) < 0 )
{
// do something
}
z = iz * 100;
if( z < 0 )
{
// do something faster
}[/as]
Share This