Upon working on my game I noticed a few more things that really ruined the overall efficiency, primarily new objects being created still (footprints, snowballs) and my mousemove function which was collecting large integers for no reason. Here are a few tips that I noticed that benefitted me.
- At the start I store an array containing a maximum of 150 footprints, that seemed to the be optimal amount. So whenever a new footprint is made, I usually take an existing footprint on the screen (one thats been on the screen the longest) and adjust its position. Since the whole screen gets filled up with footprints, its hardly noticable. I find that preloading some arrays would be better than creating new objects, and this goes for snowballs too.
- No more new objects are created. In addition to this, I tried to avoid alpha and prefered to switch the frame to an empty frame. In addition to this I used to create new objects for a Red Guy swap; its better to have a temp object available and then reuse that over and over.
- Within my MouseMove event, I had a power ticker…which meant it was incrementing an integer every frame. Not a big deal, but I tended to increment it each time THEN i would set a maximum. So now it only increments a certain number of times and then it no longer adds to it. Unnecessary math. I complained about MouseEvent’s inefficiency, but I was wrong. Sorry Adobe.
- Created more constants (ie: stageWidth and stageHeight) and I tended to create temporary ints and numbers to avoid checking the same variables over and over (ie: within boundary checking, I would check the Red Guy’s position for each border check…you just need to check the ONE position at 4 boundaries…not constantly pull the RedGuy.x and RedGuy.y position)
This seems to be the best working solution, again 50 guys is as much as I’ll go, in fact, it would be more efficient to have 50 guys for the level, but they come in waves of 10….so that means ill have 10 guys and then reuses those 10 guys for the next 5 waves. Cool eh?