In a game I'm starting to make using cocos2d, I have a subclass of NSObject containing details like the speed of the car, so that's the model. However I'm confused as to what the Controller and View are? The only other class I have is a subclass of CCLayer. In this I have the accelerometer delegate method which moves the sprites around, in the init it adds the sprites to the scene(?)
I assume it would be wrong to reference of the sprite of the car in the su开发者_Go百科bclass of NSObject which holds the details of the car?
So whats the View and the Controller when using cocos2d?
(eg in traditional apps, the Model is generally a subclass of NSObject (or just an array or dictionary) , the Controller is a subclass of UIViewController, and the view is a subclass of UIView)
I have the model as a custom class that subclasses NSObject, the view as a CCLayer which contains CCSprites and the controller as a CCScene which connects multiple models and views.
The way I look at it is, CCLayer is your view, and the custom class is the model. I see no problems in storing the sprite in the model because it's the data that represents the visual aspect of the model. If your model has a general abstracted interface and you have a separate class that connects the model and CCLayer then it's your controller. If your model and CCLayer is directly connected it's the case where you merge a model and a controller.
精彩评论