How I beat my slow FPS problems in my iOS game

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/52

Optimizing iOS Game Performance
http://www.stencyl.com/help/viewArticle/93

What to test on


The 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

gplar

  • Posts: 1115
Thanks for sharing this, Tom. I´ve followed you struggles in the forum without being able to make any sensible suggestions, and admire your persistence until you made it on your own. Should go in the ´pedia, I´ve bookmarked it in case it doesn´t.  :)

h1rnz1lla

  • *
  • Posts: 649
good to see you solved the issues!
also +1 for the share!

kiwixoats

  • Posts: 104
Thanks for the post, this is very important.

Innes

  • *
  • Posts: 1960
Thanks for taking the time to post this.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

Leaufai

  • Posts: 327
Great post, very insightful.

Electric Fruit

  • Posts: 116
Thanks for posting - very helpful.

marcwilhelm

  • *
  • Posts: 88
You are a great asset to the Stencyl community Tom, thanks for sharing.

« Last Edit: July 21, 2012, 07:34:48 am by marcwilhelm »

JensWinterstein

  • *
  • Posts: 432
A mod should either make this a sticky post or merge it with "Tips & Best Practices" in the iOS forums.
Thanks, Tom.
Get 100 Chambers for Android / iOS
Get Cubus Velox for Android / iOS or play it on Flash

- Portfolio

Joe

  • *
  • Posts: 2478
A mod should either make this a sticky post or merge it with "Tips & Best Practices" in the iOS forums.
Thanks, Tom.

Done! Nicely done, Tom!

FranAlt

  • Posts: 169
Hi

Now that my iOS game is further more developed I find myself with high usage of RAM memory, with values up to 118MB wich is really high, considering that the app weights just 12-20MB. It runs pretty well in my iPad (55-60fps) but refuses to open in my iPod Touch that has just 100MB of RAM.

I have a max of 3 atlases loaded at the same time in every scene.

Anyone know how to fix this?

Thanks!
Swipe - FREE          Cloud Run - FREE              
                                  
         iOS                                Android
    Android

dgcharlston

  • Posts: 60
Bump - Thanks this really helped