Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layer vs Scene in Cocos2d for iPhone game development

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?

like image 969
zhongshu Avatar asked Mar 05 '09 09:03

zhongshu


1 Answers

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.

like image 153
David Higgins Avatar answered Oct 11 '22 00:10

David Higgins