views:

3535

answers:

2

Using cocos2d for iPhone game development, I am confused between Layer and Scene. For example, My simple game have several "UI Pages" like main menu, highscores, game board etc.

So should I use Layer or Scene for every "UI page", and why?

+3  A: 

Reviewing SpritesDemo.m/.h, it would appear that they are using Layer, and then creating new scenes, attaching the layer and then replacing the scene on the director

@interface SpriteDemo : Layer
@interface SpriteManual : SpriteDemo

The code then does the following:

-(void)nextCallback:(id)sender {
  Scene *s = [Scene node];
  [s add: [nextAction() node]];
  [[Director sharedDirector] replaceScene s];
}

So, in short, the answer to your question would be "both", you use Layer to represent your actual "UI Page", but you attach the Layer to a new scene and replace the current scene in the director.

David Higgins
A: 

You really don't need to use a Layer unless you're getting some kind of touch input(because it's the only class in Cocos2D that implements TouchEventsDelegate). The demos work fine if you put their code directly on the scene without the Layer, so as far as I can tell they only did that to demonstrate other Cocos2D functionality(adding children, setting positions, etc).

Matt Rix