Notes
Notes: Loop/Statement Labels
Below are some notes from Christian Cantrell’s blog that I just wanted to aggregate onto my site for my own personal reference. I am not claiming this as my own content, but I’ve been meaning to add this to my notes and Christian did a great job explaining it.
Labels are a relatively unknown feature in AS3. Basically what it does is give an ID to a specific loop or statement. So when you call break or continue, you can specify WHICH loop to break or continue.
› Continue reading
Notes: Loop Optimizations 2
This is kind of an extension of my previous loop tests I did. I ran into this while making improvements to Orion. I was really surprised there was this much of a difference in speed. The discovery I made after looking into BetweenAS3 and the efforts of Joa Ebert on his AS3 particles I noticed they were using LinkedLists to manage large numbers of objects. LinkedLists are only good if the you don’t have to remove items from the list as that can be a painful experience. But adding to and iterating through the list is blazing fast as denoted below.
Notes: Positioning Optimizations
This page sort of expands upon the previous post I made on loop optimizations. I’m going to use this post in the future as a catchall for any other optimizations I run across. So for now I just have one to list, but hopefully in the future I’ll add some more.
Edit: (Sept 8th 2009) Ok I was kidding, I think I’m going to make separate posts each time. That way it shows up as a new post and people actually notice it. The “optimization” tag can be used to filter out just these posts.
Modifying a DisplayObject
Using a Matrix to modify a DisplayObject is faster than editing the individual properties.
// 1 Million runs 2578ms, 2583ms, 2572ms spr.transform.matrix = new Matrix(spr.scaleX * 0.98, spr.scaleY * 0.98, 0, 0, spr.x + pt.x, spr.y + pt.y);
is faster than
// 1 Million runs 3597ms, 3609ms, 3569ms spr.scaleX *= 0.98; spr.scaleY *= 0.98; spr.x += pt.x; spr.y += pt.y;
Notes: AIR
Some notes I’ve gathered over time in regards to AIR. As per usual, just posted up here for future reference.
Multiple Monitors
When building an app for multiple monitors, be sure to make use of the flash.display.Screen class. This class lets you iterate through all of the monitors available with access to the size and resolution of each. It also can tell you which is the primary monitor. Below is a useful function to grab the current screen.
private function getCurrentScreen():Screen {
return Screen.getScreensForRectangle(stage.nativeWindow.bounds)[0];
}
Notes: Loop Optimizations
Here is some testing I did to determine the best kind of loop to use in AS3. In the end the fastest I determined was a simple reverse while loop. Below is the results with the code for my testing beneath that. Where I could, I tried to run 1 million items in the collection. If I was unable to do that (the program would crash) I would run 500k items. From what I have learned, using the Array.forEach() is kinda expensive for what it does. Standard for() loops aren’t too bad, but the for…in() loops are even worse than the Array.forEach(). If you know of anything faster methods or maybe I tested incorrectly please let me know!
› Continue reading