views:

336

answers:

1

I am developing a puzzle game for the iPhone using core graphics implementing drawrect in a single UIView.

I would like to add a menu which is opened from a UIButton event handler.

I am not sure if I should do this via code e.g. have a menuopen flag and adjust the drawing routines and tap event handlers (manual implementation) or to go the UINavigationController route and have a completely separate view which would be activated i assume in the UINavigationController from the button event.

Currently my music and sound stuff is in a class attached to the "main" UIView in my game and initialised via ViewDidLoad.

Any advice would be greatly appreciated.

+1  A: 

You should definitely put your menu code in a different view object. Don't just redraw the existing view in menu mode. That will make your code needlessly complicated.

You don't have to use UINavigationController to swap out one view for another, however. You write code yourself to remove the game view (removeFromSuperview) and add the menu view (addSubview:) to the application's window, using transition animations if you want.

You could also use UIViewController's presentModalViewController: method to push your menu view on top of the game view.

It's hard to say exactly what you need to do without knowing more about your code, but you should absolutely definitely keep different things as different classes, instead of making one class that acts as many things depending on a mode flag.

benzado
@Benzado thanks for the tips. My gut feeling is that many OpenGLES games probably just use one view and all the in game menus etc are handled in code? Did you have any opinion on having two UIViews and simply hiding one or the other with the hidden flag?
PeanutPower
OpenGL is a different can of worms that you don't need to worry about if you're working in Core Graphics. Using hiding is probably no different than adding/removing the views, you could do that if you prefer.
benzado
Thank you Benzado
PeanutPower