Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are iOS games set up? [closed]

In all of my past iOS games I have had the game set up as a simple View-Based Application with one view controller, .h file and .m file. I set up an NSTimer set at 30, 40, or 60 frames per second that called the main run loop. Later into development, I split up graphic updates (at a higher FPS) and game calculations (lower FPS) to reduce lag. I never understood how to implement multithreading/concurrency in games as the graphics and computations are dependent on one another...

Given that I have never had the opportunity to read the source code of a "real" game, am I setting it up in a reasonable fashion, or am I taking a totally wrong approach to the main framework of the game and run loop?

I ask this because I have noticed that my apps have a lot of lag compared to other apps on the App Store (for example, my app lags horribly on an iPhone 3G, yet Doodle Jump, Fruit Ninja, Cut the Rope, etc. run relatively smoothly).

like image 441
Greg Avatar asked Apr 10 '12 02:04

Greg


1 Answers

  1. You want to use CADisplayLink instead of NSTimer for your run loop.
  2. You want to do as much drawing on the GPU as possible. This will free-up CPU cycles, and hardware accelerate a lot of calculations that you are currently doing in software. You do this by drawing your sprites in OpenGL as OpenGL textures. There are libraries that do this for you like Cocos2D. Cocos2D provides a simple API for creating and animating sprites, and it does all the OpenGL under the hood so you don't have to.
like image 80
Jay Avatar answered Oct 17 '22 12:10

Jay