Basic structure of an iOS game with OpenGL - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Basic structure of an iOS game with OpenGL (/thread-9389.html)
Basic structure of an iOS game with OpenGL - whitey - Oct 4, 2011 09:40 PM
Let me start by saying I've done lots of game dev before, just not for iOS or using Objective C. I'm going to be developing my own game engine for personal use, and am curious on the best way to structure the core of it all.
First of all, what is the best way to run the main game loop? Using an NSTimer or a classic while loop (perhaps on it's own thread)?
I would also like to use a "state" system (menu, game1, game2, etc). I would also like to take advantage of the UIKit (skinned of course), as it'd be easier to make menus and take text input (so I believe, maybe it's not so hard to make a custom UI).
I current have a GLView, which sets up the OpenGL layer and context and an instance of this view is added to the window (I avoid using nibs). However, I currently have no view controller, and am still somewhat confused on the concept. From what I understand I would need one to control input and interaction with UI? Does this mean for every GUI I have I'd need a view controller? I'd like to be able to have a menu state with many views (main, options, etc), and the game state with the GL view, an ingame GUI, and a pause menu, and maybe other ingame menus.
I'm not excatly sure how to layer this and properly handle transitions.
I would like to always have the underlying OpenGL view as you could make cool menu backgrounds and effects (such as Fruit Ninja), so that would always be my base layer. Being so, should I add subviews to the GLView, or to the window, but on top of the GLView?
Also, where would be the best place to handle my core timing and game loop and such, the main app delegate or in the GLView?
Lastly (for now lol), where should I handle input events, from the window, or the GLView?