开发者

How can I improve the "smoothness" of a 2D side-scrolling iPhone game?

开发者 https://www.devze.com 2023-01-10 20:50 出处:网络
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 up

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 sm开发者_JAVA百科oothness 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)


It's really hard to debug graphics problems with this. Try using the openGL ES instruments to find where are the bottlenecks. It's quite handy. Also, look at the WWDC videos on openGL. They're really good.

One thing I noticed is that you said "I'm rendering at only 30 fps". Does it mean you're manually setting up a timer or something? This is not a good way, instead you should use CADisplayLink to get notified when the screen wants to update. It could improve your smoothness.


To complete Mo's answer on the 30fps...

The fact that you request the update at 30fps does not mean you're going to get it. I'm not an iphone programmer, but I can tell you that if your frame rendering takes 100ms, you're guaranteed to never update faster than 10fps. And if you're actually rendering at 10fps, then smoothness is gone.

So, measure the time you take to render to get an idea of what actual frame rate you get. As to how to optimize the rendering specifically for iphone, I'll leave that to people more expert than me on the subject.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号