Game State Management

Member
Posts: 27
Joined: 2011.04
Post: #1
Hello forum. I am planning to have some sort of game state management for my iphone game but I have some questions. I would have a certain class be my "state-manager" and some other class be my "state" class. The only problem is what classes to use. For my "state-manager" class I could use either the appdelegate or a viewcontroller. I think the appdelegate class may suite me better because I can access it anywhere, including inside the "state" class to notify the appdelegate to change states. However, I'm wondering if a viewcontroller would be better to use as a "state-manager" if it has any features that would be useful but not avaliable in the appdelegate. Also, the "state" class has a similar decision. I could use a viewcontroller or a single UIView. A viewcontroller may add more flexibility with the states, for example I was thinking that the "game state" class could be a subclassed viewcontroller, and that a "game view" UIView subclass would be contained inside of the viewcontroller. I could also have a "game data" class contained inside of the viewcontroller, so that the "game view" class could access the "game data" class to find locations to move certain CALayers to (which are used as the sprites in the game). The original viewcontroller could control the timer (or display link), control a soundmanager, and maybe handle networking. However, a viewcontroller as the "state" class may be unnecessary, and a UIView class as the "state" class may be easier when using transitions from one state to the next. It would be great if anyone has some input or suggestions on this decision, and if anyone else has used something like this before.

A 14 year old app developer...god help me...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Ignore the UI* and CA* classes when designing your game. They're irrelevant. In general, your game should be portable to any other platform by removing the input, graphics and audio layers and keeping every other aspect of the design.

In other words: none of your game logic should even include UIKit or CoreAnimation or really anything other than Foundation.
Quote this message in a reply
Member
Posts: 27
Joined: 2011.04
Post: #3
Okay. I was trying to seperate the game logic from the UIKit, I was going to store the game logic and data in a class seperate from the view, inside the viewcontroller. Do you mean to keep the game data class out of the viewcontroller? I wasn't planning to port the game to any other platform, so I'm not sure this kind of seperation is necessary.

A 14 year old app developer...god help me...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Whether you ever do the port or not is equally irrelevant (though having a Mac version is incredibly helpful for iOS development). Design is mostly about what pieces of the puzzle to keep apart, and "windows, graphics, input and audio" are all things that should be as decoupled as possible from the rest.
Quote this message in a reply
Member
Posts: 27
Joined: 2011.04
Post: #5
So are you suggesting to take the game data out of the viewcontroller?

A 14 year old app developer...god help me...
Quote this message in a reply
Member
Posts: 92
Joined: 2002.04
Post: #6
I think what OSC is saying is create your own class to manage your state and send messages to your viewcontroller

Justin "LordFire" Baldock
Quote this message in a reply
Member
Posts: 27
Joined: 2011.04
Post: #7
That is similar to what I was going to do. I was going to have my game data class contain all the data and logic and keep that away from the rest. The viewcontroller would handle the timer and tell the game data class to update itself, and would also tell the view class to update itself. When the view updates itself, it needs to get the postitions of all the game entities from the game data class and update all of its CALayers that correspond to each entity. If I did this, the view class would need to be able to fetch the data from the game data class, possibly via a reference to the game data class that is setup when both classes are being initialized. Is this what you are concerned about? The only class so far that deals with any Core Animation or view-related classes is the game view class, so the game data and logic doesn't interact with any of the view-related classes. I'm not sure I understand exactly what you think should be changed. Can you elaborate on this?

A 14 year old app developer...god help me...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Data Management ajrs84 5 3,726 Mar 31, 2012 08:32 PM
Last Post: OneSadCookie
  How do you create enums for state charts in ObjC? riruilo 7 6,872 Mar 27, 2010 11:50 PM
Last Post: AnotherJake
  Taking Pictures of Game State inside an app Bersaelor 7 5,230 Nov 3, 2009 05:07 AM
Last Post: Bersaelor
  Save game state using Property list or Text File? Graphic Ace 2 3,585 Apr 6, 2009 03:48 AM
Last Post: Graphic Ace
  iPhone memory management mlady 2 3,161 Mar 10, 2009 03:10 PM
Last Post: mlady