Hey all, I wanted to add a post about how I have learned to optimize my game for iOS. These are a list of tips that compliment the information you’ll find in the articles below. Hopefully some of them will help save you some time and get your game running faster. These suggestions will apply to version 3 as they’re general tips.
Optimizing Game Performance
http://www.stencyl.com/help/viewArticle/52Optimizing iOS Game Performance
http://www.stencyl.com/help/viewArticle/93
What to test onThe flash player and simulator aren’t any use in testing your game’s performance. You have to do a proper on-device test to see what your frame rate is. I’d recommend splashing out on a crappy old ipod 2nd Gen. It doesn’t matter if it’s bashed about and scratched. Even if you plan to target a higher version of the device, the 2nd gen will show you where the clogs in your code are. Testing on the latest hardware will make everything seem rosy, when really there could be some problems being masked by that powerful hardware.
1) Be careful using Game Attributes. They’re super-easy and convenient to use in a game, as they let all actor and scene behaviours access them. But GETTING or SETTING them from a When Updating event means that they’re accessed up to 60 times per second. As your game grows and you rely on them more and more, your Frames Per Second (FPS) will start to drop rapidly.
This is one of the things that caused me a lot of problems.Instead, set attributes normally on your behaviours (the regular BLUE kind), and when you need to, share them with other actor and scene behaviours with the get and set blocks under Behaviour -> Attributes. I’ve tested this and it has the same effect as Game Attributes, but none of the processing cost. I’m able to maintain a really high FPS even on my cranky old 2nd gen ipod touch.
2) If you want to find out where the resource hogs in your game are, disable all scene behaviours, and all actor behaviours. Then, enable ONE behaviour at a time and test on device. If you hit a problem with your FPS, go into the behaviour and disable all EVENTS (by clicking on the check-boxes beside each one). Then, yup, you guessed it, enable them one at a time, testing on device for each one.
This process will take you a long time, but it is the only way I’ve found to track down individual behaviours and events that are hogging system performance. Have a book on hand or read the forums while it’s compiling. You’ll go mad sitting waiting for it to pop up on device. ;-)
3) Your main focus should always be on the When Updating events. These happen 60 times a second and it doesn’t take much to slow things down on iOS.
4) MATH happening every single frame can cause problems. Some math is more intensive than others. Trig, for example. Use IF loops wherever possible to stop things happening every frame, and make things happen only when you need them to.
5) A very useful trick is to go through the code in a When Updating event and put a print [1], print [2] and so on in each IF code block, then run a test on flash and press ~. Why do this? It will show a number for each part of your code that is running every frame. Kind of like when mechanics fill stuff with smoke to see where the holes and leaks are.
If you see a long line of 7 7 7 7 7 7 , then check where you put the print [7] block. That code is running EVERY frame and could be causing problems.
6) Once the game appears on your device, give the console 20 seconds or so to settle down before you decide whether the frame rate has dropped since your last change. It seems to take a little while to stabilize sometimes and give an accurate average FPS.
7) Reboot your device before each day’s testing. Some apps or processes might be running in memory that could mean you get a less than accurate picture of your games speed. Rebooting your device will clear everything out and you’ll start with the same conditions each testing session.
I think thats it for now. I’m still learning the ropes but I’ve made some good progress this week and my game is running much faster through doing these steps.
Please move this if I've posted it in the wrong place.
Tom