2D Game Stutters

Nibbie
Posts: 4
Joined: 2009.04
Post: #1
I'm developing a 2D game and I'm using a NSTimer set at 1.0/60.0 to call my gameLoop method. I'm also using the accelerometer, set at 1.0/100.0 to move the player around the screen which seems to be a bit jittery. I should mention that I'm using Core Graphics for all my drawing. ie. offscreen bitmap then I blit that to the screen in my drawRect method of my UIView.

My animated background and sprites (approx. 30 items) seems to move very smoothly when running on the simulator. However, when I run on the iPhone the game starts off running smooth and then I start to get jitters/stutters and sometimes even a pause. I have used instruments to check for leaks and everything looks good there. This is my first attempt at a game. Any ideas on why this would be happening?
Quote this message in a reply
⌘-R in Chief
Posts: 1,261
Joined: 2002.05
Post: #2
If you're using Instruments, you can do a speed profile and it'll show you what's slow. It'll surely be the drawing itself.

Trying to draw many things at 60fps with CG on an iPhone likely isn't going to happen. You need dedicated help from the hardware. IOW - OpenGL.
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2008.10
Post: #3
I don't have any idea if this would be the cause but why to you do have such a high frequency for the accelerometer?

It doesn't make sense (to me) to have it set higher than the actual frame rate of the game. I use 1/60 for my timer and 1/45 for my accelerometer and have more than 30 objects on screen with no problem... something easy to try anyways...
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.04
Post: #4
sumiguchi Wrote:I don't have any idea if this would be the cause but why to you do have such a high frequency for the accelerometer?

It doesn't make sense (to me) to have it set higher than the actual frame rate of the game. I use 1/60 for my timer and 1/45 for my accelerometer and have more than 30 objects on screen with no problem... something easy to try anyways...

Hmm... not sure why I choose that value. I will give 1/45 a try and see what I get.

Thanks.
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.04
Post: #5
TownDrunk Wrote:Hmm... not sure why I choose that value. I will give 1/45 a try and see what I get.

Thanks.

Well... I have been rewriting my game using OpenGL and this has been quite a learning experience. I cannot believe the difference in speed and smoothness. I guess everyone here in the forums who says "you need to use OpenGL..." is right and has probably gone down the same path as I have to get here.

Thanks
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  AVAudioPlayer stutters the game when changing song AdrianM 0 3,898 May 13, 2010 03:59 PM
Last Post: AdrianM