Archive for January 28th, 2009|Daily archive page

iPhone Gaming Framework: Screen Manager Update

I don’t have time to write up a complete tutorial, but I will soon.. but I wanted to show just how the screen manager works. First, the video so you have an idea;

Click here for iPhone Screen Management Demo
Since I am on OSX, I am working on a way to record videos and upload them to youtube like I did with windows. When I do, I’ll embed them into the page again. For now, this solution works.

As you can see, the transitions and everything works just like an XNA project would. As said before, I converted Jeff’s GLViewController to be my screen manager. To use it, what you would do is something like the following;

TitleScreen *newScreen = [[TitleScreen alloc] init];
[controller addScreen:newScreen];
[newScreen release];

the addScreen method will retain the screen, load any content the screen will need in the game, and then add it to the screens array. Since the controller is handling the screen, and has retained the screen, we then need to release it. It is now in the controllers hands!

The controller knows if a screen is a popup screen (ala dialog box) or a full game screen (ala battle screen / inventory screen / main game screen, etc) and will transition based on what kind of screen it is. Popups get no transition, full screens will get the fade effect seen in the video. Same for transitioning off. To exit a screen, you would do the following;

if (condition == true)
    //in the game screens "update" method. Self refers to the game screen
    [self exitScreen];

the game screen will handle any transitions if it needs to.. popup’s will just pop off the stack.

One other thing that I found really interesting, was input handling. since the iPhone uses an event like system, the moment you touch the screen the iPhone sends a message saying “HEY! I’ve been touched!” What I’ve done was create an InputManager class that takes that input, and stores it in either the previousInputState, currentInputState, or queryInputState. Obviously the previous and current input states are self explanitory, the queryInputState is the state that has happened but has not been committed quite yet (meaning, the screen manager has not updated the input state quite yet) The screen manager would then update the input state, and filter it to the top-most screen.

What I would like to do, is create a project template for this framework for any 2d developer wishing to get started in iPhone Games Development. Obviously this template will be an ongoing project, and as improvements are made the template will be updated. My problem, is google has been unhelpful for trying to create a template file. If anyone knows of a good tutorial to look at, or good reading material, please send it my way! I can be reached at my listed email address ( ) If I can’t find a way to convert this into a template, the best way to distribute this would be to zip it up and that would be a pain when you want to start a new project.

Later this weekend, I will try to do a full writeup of the screen management system. Until then, happy coding!