Search code examples
cocos2d-iphonekobold2d

Layer or Scene?


Learning cocos2d/kobold2d and puzzled by the scenes and layers. As I understand a scene usually contains layers where the layers contain UI elements like buttons and all the logic.

My first project is based on the kobold2d helloworld example and there I see that the layer is subclassed from CCLayer instead of CCScene. While searching about this topic I saw the helloworld example is with the layer derived from CCScene. Anyway, why does the helloworld example not derive from CCScene while it apparently did before?

I looked at some other examples (doodle and pinball) and there also CCLayer is used and not CCScene.

Is there a definitive guide on scenes and layers? Does kobold2d promote using just layers or how should I look at this?

Regards,

Rob


Solution

  • In Kobold2D, if your first class derives from CCLayer instead of CCScene, Kobold2D silently wraps it in a CCScene object. That way you don't have to write the +(id) scene method anymore.

    This is great for scenes that only use a single layer, less code to write. And you can still add more layers to the scene by adding them to the layer's parent (which is the scene): [self.parent addChild:..]

    Btw, if your first class is indeed a CCScene class or it implements the +(id) scene method, then that scene is used.