AS:Main
Just a few general tips I find extremely helpful to keep filesize down and runtime speed up in games and movies.
The .fla file bloat
Every time you File -> Save in Flash, the un necessary data you may have deleted from the stage or library is not removed. See it for yourself by importing a large media file, saving, then re opening and deleting it from the library before saving again. The filesize will still remain gigantic. Flash tries to keep saving time and memory use down by not removeing the waste.
I'll state now that this file bloat does not affect your .swf in any way. This fix is to merely reduce the hard drive space taken by your .fla ; and reduce the time taken when loading it up.
Flash MX2004 has the File -> Save & Compact option, which can be used to remove this disregarded data when saving. But in versions prior to MX2004, this optons is not avalaible.
For the many users here that prefer Flash MX and even ver.5(God knows why), the fix is to File -> Save as, and save under a different name. This has the same effect as File -> Save & Compact (in MX2004).
Anti-Aliasing
Anti-aliasing is a technique performed by Flash to try and smooth out jagged vector curves. It is rather processor intensive, and can cause significant slowdown (in higher framerate games and movies) if certain techniques are not followed.
Anti-aliasing is needed more when the contrasing colours appear adjacent to eachother. You can save on memory use by trying to make curved lines a similar colour to the background where possible.
Anti aliasing can be turned off by switching the movie's quality to "LOW". This is where the tradeoff occurs between running speed and rendering quality. When running at low quality, I would suggest several ways to hide the jagged curves that will appear.
-Again, use non-contrasting colours , so the jaggies will blend in.
-Try to use horizintal and vertical graphics wherever possible, so less jagges edges will be present.
-Have fast moving shapes, the edges are a lot less noticable
-An interesting one here - use pixel fonts, such as old NES and Atari style ones, these look pretty much exactly the same in low quality.
Bitmaps / Vectors/Graphics
First of all I will say Always try to avoid reducing alpha on bitmaps. Now this is a huge performance hinder on all movies, rendering transleucent or transparent bitmaps (_alpha < 100) is a lot of work, even more so if they are moving.
Using vectors and bitmaps:
Bitmaps can move a lot faster than vector graphics in flash. When there is little screen activity, this statement is not true, but when there are lots of objects (e.g. characters) moving accross the screen, bitmap artwork would be a better options, as it saves flash having to re define and re draw many co ordinate points each frame.
For bitmap sprite graphics, .PNG files have been highly recommended for rendering speed on stage.
Another point worth covering would be offstage content. In .swf's, if objects such as characters and enemies are positioned offstage, set ready to be brought in, or after being sent off (etc.) Creating an empty frame inside the movie clips themselves, and sommanding the mc to gotoAndStop on this frame while they are offstage can save on speed.
The offstage content is still rendered by Flash, even if it is not visible to the user. Having a blank frame is an excellent idea for RTS(realtime strategy) style games (command & conquor style), or any others where the user can scroll to a different area of the map, leaving enemies and players offstage. -Could also be implemented in movies for scrolling backgrounds and such.
Actionscript Optimisation
Just a few key points here, generally, a tradeoff occurs between clean, reusable code, and efficient faster running code.
Try to minimise the amount of different onEnterFrame handlers in the game/movie
Using too many of these handlers reduces run speed. Where possible, apply the required actions inside ONE of these handlers that can run through the entire timeline, instead of using many.
I've amazed myself at the amount of times I can substitute an onMouseMove handler instead of an onEnterFrame for things like cursors and scrolling shooter games, not only does mouseMove only apply when actually necessary (when the mouse moves), it gives a smoother feel (so far I have not noticed any slowdown despite the higher frequency).
Using loops
It is apparently believed that
"A typical game loop where you attach movieclips to a target mc.
Using the while loop instead of for results in better performance"
-Taken from gotoandplay.it
I'll note that the while loop is proven to be the faster running loop, as it takes less information in, I would still reccomend the for loop, unless you are really desperate for performance.
Multiple var Declaration
You can use this if you are really squeezing, people running websites with flash interfaces have given this method, I wouldn't really say it is of great use to movie.game developers.
Intead of:
a=0;
b=0;
c=0;
d=1;
e=1;
You can use:
a=b=c=0;
d=e=1;
Always declare local variable in functions
Always decare your local variables using var. Making sure the variables used inside your functions are local makes them easier to access by the flash player, resulting in faster running speed. If you declare variables using name = ;, they will be declared globally, and will take up more of the movie's virtual memory.
Accessing Local Variables
When accessing local variables, using the with operator as opposed to repeatedly using this. saves on typing & CPU usage.
e.g Using:
with(this){
a = 1
b = 2
c = 3
}
Instead of:
this.a =1
this.b = 2
this.c = 3
Key Optimisation
This is one i came accross and found interesting.
Using:
keyDown = Key.isDown;
keyLeft = Key.LEFT;
if (keyDown(keyLeft)){}
Instead of repeating:
if(Key.isDown(Key.LEFT)) ;
More on Binary Increasement
Hope there wern't too many spelling mistakes! Leave any feedback!