Oldschool tunnel (AS3)

Oldschool tunnelAnother oldschool effect done using Actionscript3. Somebody complained about the speed? It was not me :-). That demo is very fast and the best thing is that I am using again a ByteArray. Some calculations are done using shifting operators and the tunnel is only 128x128px large. I am using a second BitmapData object to scale everything up to 400x400px and this is very fast now.
The animation is done using the getTimer() so it does not depend on the framerate (which is set to 120). The texture is a simple array of colors which is generated at the start using the XOR operator. It is very nice to have a simple texture for testing and developing.

Another thing is the for vs. while battle. I did some speed tests here. while using i++ < n was slower than the for equivalent. Using --i > -1 has the same speed as for.

[as]
// the for loop (~40ms)
for ( var i: int = 0; i < 600000; i++ )
x += 1.25;

// same speed as for (~40ms)
var i: int = 600000;
while ( --i > -1 )
x += 1.25

// slower (~110ms)
var i: int = 0;
while ( i++ < 600000 )
x += 1.25
[/as]

Maybe it was me doing something wrong but this would be nice because I like the for-oneliners.

1 Response to “Oldschool tunnel (AS3)”


Leave a Reply