Well this was an annoying turn of events.
I had some time off from work this past week and my plan was to sit down and crank away on making a playable demo for this game over my extended weekend. Yet somehow I'm actually a step backwards, or rather a few steps backwards than where I was 4 days ago! What happened you ask? Performance Optimization. That's what happened.
Without getting too elaborate, as you continued to play each round, the game slowed down. Not a little, I'd just deal with it if it slowed down a little, but no - It slowed down TREMENDOUSLY. So much so that it became unplayable by the third or fourth round of gameplay. So I did some research online about what could be causing the memory leak in the gameplay. It turns out I really AM as amatuer at this as I predicted, because I felt like every Flash forum on the web was yelling at me - and these were posts written up to 3 years ago!! They were yelling at future Mark!
Whatever, it happens, right? So the next logical step was to figure out what the MAIN source of my memory leakage was. I started with something most websites called out the most - Event Handlers defined through ENTER_FRAME events... To put in layman's terms, functions that are being called on a continuous loop. From what I've read, the rule of thumb is to have only ONE Enter_Frame Event Handler. I had two. So I combined all the functionality being used in both handlers into ONE Enter_Frame Event Handler.
Still slowed down. Not even the slightest change.
So I moved on to the next most common culprit - Timers. A Timer is what it sounds like, it's a countdown. For example, when the CPU performs a block, I want it to wait half a second before it stops blocking. You would use a timer for this that counts down half a second and then tells the computer to stop blocking. Like the Event Handler, the rule of thumb was to have only one Timer... I had about 15 (with more to come!). So I went through all of my code and replaced the timers with another method of timing that supposedly is more performance-friendly... Still no luck.
Nothing was working, although my code was beginning to look A LOT cleaner. So I took a step back from code and looked into the actual files and images I was using to create the game to see if something there was sucking up all that sweet, sweet memory... Sure enough, I stumbled upon a bunch of Text which was using up memory to render. So I removed the text and changed it to images.
On the bright side, this reduced the file-size of the game, but did nothing for performance. It still slowed down after a couple rounds! By this point I was getting ready to blow my brains out. This all sounds like it took place over the span of about a half hour, but this was 3 days in! I was actually considering calling it quits for good on this game (not exaggerating, I was planning out what I'd write in the blog about why I straight up quit working on this stupid game), but I had one more idea to try out... Actually do a test to see where the memory leak first occurs during gameplay. It was a simple command to put in my code which would display the amount of memory being used while I played. At the beginning of every round, there was a huge spike in memory which wouldn't go away. It had nothing to do with the code and everything to do with what objects I was throwing on my stage.
Basically after every round, I removed all the elements from the stage and re-added them for the following round. I'm too lazy to explain, but the solution was to handle this with code rather than manually placing the objects on the stage. It turns out it was a very quick and simple fix that I somehow managed to turn into a 5 day, mind-melting, soul-crushing exercise. But I'm happy to say the game no longer slows down. Boo yah!
The bad news, however, is that I had to remove the time limit because I haven't figured out a way to manage this without using a Timer (though maybe the timer isn't a bad idea considering timers weren't the root cause of my issues). I may have created a few bugs along the way as well, mainly involving the CPU Player's functionality. But screw it, this game is going to be buggy no matter what given my low-level skills.
I suppose now I'll retry what I intended to do this weekend, fingers crossed. My 1 year old has a fever, though, so I doubt I'll get much done this week. I won't bother posting a progress video because what's the point? You've seen it all and more... Crap, I don't think I have anything to post visually. This is purely a text-only post now. Sorry. I'll doodle something for you tomorrow. For now, sleep.
Lots of letter "Z's",