Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cocos2d and MVC

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 subclass 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)

like image 570
Jonathan. Avatar asked Feb 26 '23 00:02

Jonathan.


2 Answers

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.

like image 137
Chris Avatar answered Mar 06 '23 05:03

Chris


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.

like image 43
MHC Avatar answered Mar 06 '23 03:03

MHC