We create the best entertainment in the world. Be sure to visit me at my homepage! I'm always working on a new game or something interesting!
Posted by jrjellybeans on Sep 14th, 2010
As I keep mentioning, working on this new game has taught me a lot. It’s my second game working with Actionscript, and I’m really enjoying the process. Compared to where I was just a couple months ago, it’s amazing to see how far I’ve progressed.
Within this time, I’ve been able to figure out a couple of neat things about Actionscript 3 optimization. You can actually find a lot of these tips if you do a Google search of “Actionscript 3 optimization,” but I’m going to re-iterate them and my thoughts behind them here:
1. Don’t create new Geometric Objects if you don’t have to.
If you didn’t know, I’m using the blitting technique that’s highlighted here (8 bit blitting example) and it’s a great way of getting more familiar with the basics of blitting. Somehow because of the way that I adjusted the code, however, had my Movie Clip objects creating new Points and Rectangles every frame because it was easier.
It just never ocurred to me that I could just change the properties of the Point and save a ton of time and processing power.
2. On that note, don’t create any Objects that you don’t have to.
This is actually something that I didn’t end up doing for Platform Explorer, but I promised myself that it would be something that I would use in the next game.
My games run via a basic setup:
1. a “CONTROLLING OBJECT” is created that will oversee what will happen to every object,
2. the CONTROLLING OBJECT creates all of the smaller objects that it will need for a room,
3. the CONTROLLING OBJECT calls every objects’ tick event and drawing event as well as handles keyboard input,
4. when the room is finished or the CONTROLLER isn’t needed anymore, the CONTROLLER performs every objects’ death event and removes them from the stage. Then, the CONTROLLER is removed by a new “controller object”.
So, basically, I constantly have a bunch of objects that are created, manipulated, and then destroyed. Since I was using Game Maker in the past, I never really worried much about RAM usage and such. It always seemed that a room was it’s own universe and moving from room to room pretty much “reset” things as far as memory was concerned.
In these flash games, however, it’s a critical thing that memory is managed properly. Even though the objects are removed from the stage and are effectively destroyed, sometimes the garbage collector seems to miss an object or two, leaving it not doing anything and just taking up space.
After thinking about it for a while, I finally realized that I could probably just create pretty much every object that I needed at the beginning of the game and, then, determine a way to turn them “off” and “on.” Basically, I’d be reusing the same objects throughout the entire game rather than constantly creating and destroying objects…
3. Setting an objects’ “mouseEnabled” property to false helps with speed.
I read this somewhere, but I haven’t noticed any exact drop in speed. Still, it would seem reasonable to me that it would help.
If anybody can confirm or deny this, I’d love to hear about it!
4. Call stop() on a Movie Clip helps with speed as well.
This is also something that I read, but haven’t experienced much in the way of speeding up or slowing the game. Because none of my objects have anything on a timeline (all of my code is done via AS files), I’m wondering if this even registers.
But, I did it anyways cause I’m a slave to what I read on the interwebs…
There are actually a bunch more, but I noticed them in pretty much every optimization article that I read. These were ones that I didn’t really seem to find often and they’re pretty simple to do once you get the hang of it.
If you happen to think of anymore, I’d love to hear it!
The Platform Explorer demo is coming soon. Right now, there is nothing on the page, but I should have it up by the end of today.