Game Development Community

Locking FPS

by Scott Wilson-Billing · in iTorque 2D · 02/03/2010 (11:02 am) · 5 replies

Hi,

I have finished most of the scene objects in my game and am getting 35-60 FPS on the 3GS, however, I get some noticeable stutters from time to time, especially when objects are first introduced (I have preload set to true on the scene objects). I was wondering if:

a) can I lock the game to a set FPS e.g. always 40 FPS

b) will this help "smooth" out the jumps between low/high framerates

Also, any ideas what might be causing the stutters - I assumed it isn't memory as I preload everything for the scene and once the initial stutters are over it runs fine.

Cheers

#1
02/03/2010 (11:10 am)
a) As long as you aren't on the 3GS you will rarely see 40FPS, granted ;) Also you can't have 40FPS. The screen is VSync enforced, as such you can only have natural fractions of 60 -> 60, 30, 20, 15, 12, 10, ... from the hardware side
Also, you can't lock it at 40 FPS if the performance just dips.
Given that you get dips down to 35FPS on the 3GS, that basically means your game is unplayable on older devices (dips to 15FPS are pretty granted)

b) No. The jumps come from incorrect handling on the T2Di user side. the two major things that cause such massive spikes are:
1. Creation and Destruction of scene objects all the time instead of pooling them for later reuse (projectiles etc)
2. Heavy usage of the integrated physics which is sadly far from optimized. See the Box2D thread on the TGB Boards for a potential replacement of it with a much better performing system
#2
02/03/2010 (11:25 am)
Thanks Marc, I'll have a go at pooling the objects to see if I can smooth stuff out - the dips seem to coincide with some cloning that I'm doing, so a pool would be a better solution. I used an effects pool and that made a significant difference so now I'll have a sprite pool. Physics wise I only really have movement and some moveto stuff.

I do have a question with regards to animations, bear in mind I'm new to writing games ...

Does iTGB have a single in memory copy of an animation and then track the current frame for each scene object that shares the animation or does each scene object have it's own copy - assuming I am using the same animation datablock?
#3
02/03/2010 (12:16 pm)
One question about the pool, when I create the sprites in the pool do I assign the scenegraph and set visible false or should I just assign the scenegraph when I take them out of the pool (and remove it when putting back into the pool).
#4
02/03/2010 (3:40 pm)
If you're feeling brave, iPhone OS 3.1 has an actual framerate locking interrupt (CADisplayLink) ;)
You could lock it to 30 or 60, depending on detected GL ES levels then. That would of course rule out those slowpokes who are still not on the latest OS.

(And help the movement ;)
#5
02/05/2010 (12:05 pm)
Okay, I thought I'd add an update to this thread. I did as Marc suggested and added object pooling for static and animated sprites.

Static was straightforward and for animated I automatically put the animated sprite back into the pool at the end of the animation (onAnimationEnd callback). I did have one gotcha and that was that the client of the pool has to set the animation name every time the animation is removed from the pool - otherwise the animation is in a finished state and will not play, callback wont be called and it wont go back in the pool.

Object pooling has made a difference in smoothing out the game - I load the objects into the pool at the start of each level.