views:

45

answers:

1

Hi, I've got a question about the Model View Controller (MVC) design pattern for iphone games.

Let's say I have a simple game that uses a ViewController. So this view controller has an associated window/view and takes player inputs of buttons sliders, etc.. on this view.

Now I also have a subview of the ViewController's main window/view and I actually do some animation of various polygons in this subview. I also want to take touch events in this subview.

My question is, in the subview, I've got all the user touch code and animation code as the player's touch input affects the animation directly changing rotation etc.. There's a lot of variables in my subview class. Am I violating the MVC design? Should I delegate this stuff to another class or the view controller?

Many thanks

A: 

It depends on what you're trying to accomplish.

Let's assume you want your game to run on an ordinary PC, as well as the iPhone.

Obviously, you'd want to isolate all of the code specific to the iPhone, which includes the touches. I'm assuming you'd want the animation on both versions of your game, so that would be part of the controller, or perhaps the model. Rendering the animation would be part of the view.

The easiest way to determine which functions belong in the view, and which functions belong in the controller, is to imagine porting your application to two different viewers. It doesn't have to be a PC and an iPhone. It can be Android and an iPhone. :-)

Gilbert Le Blanc
cool thanks. More specifically, if my custom subview has the touchesBegan etc. callbacks, how do I make these communicate with my controller class?
songBong
Think about what concepts the touches accomplish. I don't know your particular application, but general concepts like zoom in, zoom out, previous image, and next image come to mind. Your view is concerned with touches. Your controller handles the concepts that are applicable to your application.
Gilbert Le Blanc