Cocos2d and MVC

In the game that I am starting to do using cocos2d, I have a subclass of NSObject containing details such as car speed, so that is the model. However, I am confused as to what Controller and View are? The only class I have is a subclass of CCLayer. In this case, I have an accelerometer delegation method that moves sprites around, in init it adds sprites to the scene (?)

I suppose it would be wrong to refer to a car sprite in a subclass of NSObject that contains car parts?

So what is View and Controller when using cocos2d?

(for example, in traditional applications, the model is usually a subclass of NSObject (or just an array or a dictionary), the controller is a subclass of UIViewController, and the view is a subclass of UIView)

+4
source share
2 answers

As I look at this, CCLayer is your view, and a custom class is a model. I do not see problems with storing the sprite in the model, because this is data that represents the visual aspect of the model. If your model has a common abstract interface, and you have a separate class that connects the model and CCLayer, then this is your controller. If your model and CCLayer are directly connected, this is the case when you combine the model and the controller.

+3
source

I have a model as a custom class that subclasses NSObject, a view as CCLayer, which contains CCSprites, and a controller as CCScene, which connects several models and views.

+5
source

Source: https://habr.com/ru/post/1340828/


All Articles