I’ll throw my hands up and admit it! My current project is built from a couple of demos provided by Corona to get users more familiar with the product. While I assumed that Corona would have the best algorithm for the job, I recently learned I was dead wrong.
(Pretend this is an Android 🙂
Just yesterday, I started actual level design in preparation for the beta release of my game. Once I finished 12 levels, I gave the game to my girlfriend to try out. She isn’t much of a gamer, and was able to finish all the levels with only a couple health upgrades, which told me I might need to up the difficulty a bit. Bug wise, there were only a couple noticeable things of which I already knew about. All in all, I was satisfied with my girlfriend’s play-through at this point. It was when the game was closed and she handed the phone back to me when I realized…the battery had drained 30% in the 20 minutes that she played!
I quickly scrambled to find a guide to narrow down the issue. Searching the Corona SDK site, I found this article on Performance and Optimization, which I firmly believe is something every Corona developer should read before publishing a game to the market!
Regarding battery, it was noted to minimize the usage of the following:
- Network traffic
- GPS
- Accelerometer
- Disk read/writes
After some thought, it was clear the (4) was the trap I fell into. I used the demo Corona code to handle parallaxing in my environment, easily a trap that any beginner in Corona could fall into. In short, the code was fetching the image from disk, creating the object off the right side of the screen, scrolling it across the screen, and then destroying it. I had multiple background images doing this, as well as the destructible objects that flew at the player, so it was obvious that all the disk reads were taxing the phones battery life.
Lessons Learned: When developing a solution to a problem, keep in mind the inefficiencies and try to re-use objects and functionality when you can. While “brute forcing” a solution may be the easy way out, you will eventually need to redo it a more elegant algorithm. Don’t be lazy…challenge yourself a little!
Don’t forget to check out my game to see what I’ve been talking about! Alley Avenger