0

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

Rob
  • 165
  • 1
  • 1
  • 11

1 Answers1

1

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • thanks! that explains something.. is this mentioned somewhere in the documentation? and I can just change the implementation of the first layer back to ccscene? what is the benefit/use of the +(id) scene method? – Rob Aug 27 '12 at 09:29