Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working on a relatively simple 2D side-scrolling iPhone game. The controls are tilt-based. I use OpenGL ES 1.1 for the graphics. The game state is updated at a rate of 30 Hz... And the drawing is updated at a rate of 30 fps (via NSTimer). The smoothness of the drawing is ok... But not quite as smooth as a game like iFighter. What can I do to improve the smoothness of the game?

Here are the potential issues I've briefly considered:

  • I'm varying the opacity of up to 15 "small" (20x20 pixels) textures at a time... Apparently varying the opacity in this manner can degrade drawing performance

  • I'm rendering at only 30 fps (via NSTimer)... Perhaps 2D games like iFighter are rendered at a higher frame rate?

  • Perhaps the game state could be updated at a faster rate? Note the acceleration vales are updated at 100 Hz... So I could potentially update part of the game state at 100 hz

  • All of my textures are PNG24... Perhaps PNG8 would help (due to smaller size etc)

share|improve this question
add comment

5 Answers

up vote 4 down vote accepted

I'd recommend using CADisplayLink to manage your loop rather than NSTimer. It's synchronized to the screen refresh.

Are you updating your graphics positions on the screen at a fixed interval or is their movement based on the time elapsed since the last update? Occasionally the iPhone stutters, if you don't take account of it the animation can look jittery.

share|improve this answer
    
Ok thanks. I tried out CADisplayLink and it seems to work. When I set the animationInterval to one (which I think corresponds to 60 fps on the iPhone) the animation looks much smoother. –  MrDatabase Aug 8 '10 at 18:38
add comment

30fps is probably your problem?

Some/many people will try to tell you that 30fps is just fine. But really, it's not. While 30fps is certainly 'playable', it's never going to be 'smooth', especially for a fast-moving 2D scroller, and especially to any games enthusiast that's had a taste of 60fps.

2D games on 16bit consoles and arcade machines ran at 50/60Hz for a very good reason — it looks far, far smoother than 25/30, especially for 2D scrolling games. Back then, 60fps was almost the definition of 'arcade quality'. These days, many developers are prepared to sacrifice that smoothness for better image quality (better screenshots) or shorter development time (less time-consuming optimization work).

Unfortunately, I can't help with the iPhone specifics. I get the impression that 60fps on iPhone/Android isn't easy to achieve — although a few do manage it. (The iPhone port of Pinball Dreams being one example.)

share|improve this answer
1  
I worked on a PS2 game that had a "60fps" and "<=30fps" mode. While the switch between them was nearly seamless, it was trivial to see which one the game was in with visual inspection. 60fps was far smoother. Ever since then, I've targeted 60fps for all my games. Strongly recommended if you can manage it (my games tend to be low-CPU so I can.) –  ZorbaTHut Aug 9 '10 at 18:25
1  
That is certainly the conventional wisdom. Mike Acton recently questioned the conventional wisdom, and posted his fairly rational thoughts over here: insomniacgames.com/blogcast/blog/mike_acton/1503082 –  jpaver Aug 9 '10 at 18:43
1  
The main reason for the lack of 60fps games on the current generation of consoles is the GPU cost of the switch to HD, and the expectation of very expensive lighting/shadows/shaders and post effects. Unfortunately, to hit 60fps on these machines seems to require sacrificing just too much 'screenshot quality' for most developers to accept. Maybe next-next-gen will bring back 60fps? 30fps racing games in particular just don't do it for me. –  bluescrn Aug 9 '10 at 21:32
add comment

I hate to be nitpicky but....wouldn't trying your suggestions answer them? Like PNG8 vs 24....give it a shot? Convert them after loading and see if things improve?
30fps should be smooth enough for a game, but my experience has shown that you have to be very careful (at least on my 2G testphone) to actually maintain 30fps....I'd get a spike every half a second or so throwing me one frame off, so it is crucial that your code is framerate independent. Have you verified that you don't have those spikes?

share|improve this answer
add comment

Another thing to watch out for with 2D scrolling games:

Are you scrolling a nice constant number of pixels per frame?

If you're scrolling 2 pixels one frame, then 3 the next, then 2, for example, that will add a bit of judder. If you're working with a 3D API, and scrolling some arbitrary speed, like 2.73 pixels per frame, that may add sub-pixel 'wobble'

If you are able to target a fixed framerate, try to ensure that the character's walk/run speeds are a whole number of pixels-per-frame.

share|improve this answer
1  
Good point, although I do wonder how Mario handled this as it's a game known to use subpixel values for its character speeds, and therefore must have the same for scrolling. I wonder what the perceptual result would be of scrolling at 2 pixels every odd frame and 3 every even frame. Maybe that is where 60 wins out over 30 as the perceptual discrepancy is less. –  Kaj Aug 8 '10 at 21:52
add comment

Don't trust the 60Hz hype - it is partly misinformstion. 30fps is perceived as smooth by the human brain (anything over 18fps is perceived as motion) - movies have been shot at 24 fps for the majority of the past century without people thinking they were not smooth. There is one caveat though - the interpolation has to be correct. If your timestep is not compensated properly the glitvch will break the illuision, even at 60fps - this is something that movies obviously never suffer. The only difference between 30fps and 60fps (given proper interpolation) is streakiness, since the brain will internally also try to blend the frames, and compensation for the fact (less of an issue with LCD) that the frame slowly fades between every redraw out and thus you see a wobble. Regarding the streaking: An eagle's eye registers frames at 2Hz, so when it sees a mouse running on the ground it sees a dot at place a, a dot at place b and the brains interpolate this to a line, which is why it can see the mouse from such height - streaking.
The only thing that 60fps gives is that, if your interpolation is not done right, the glitch is less and thus less disturbing to the perception of smoothness.

share|improve this answer
1  
Somebody really needs to make a little demo app to show the immense difference between 30fps and 60fps for common types of motion (In particular, 2D scrolling slow, 2D scrolling fast, and into-the-screen FPS/driving style motion) It could also show the difference between vsynced and non-vsynced updates. I think this would convince the majority of 'unbelievers' that 60fps is far smoother than 30fps. And that 250fps+ with no vsync is just silly. I do think this varies from person to person, some notice the difference a lot more (such as those that played 60fps arcade games back in the day!) –  bluescrn Aug 9 '10 at 17:16
1  
Okay, I'll rephrase my wording. Vsynched vs non-Vsynched is obvious. 30 vs 60, yes 60 will be smoother (no doubling, less interpolation for the brain), however 30 fps will be perceived as smooth (60 as smoother, but 30 won't jar the eye unless you have very big movements or high contrast as with an in the screen racer). My biggest problem is that I prefer constant 30 over 60 with occasional drops as that really jars the eye. –  Kaj Aug 9 '10 at 17:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.