Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following simple game: 20 squares floating around an iPhone's screen. Tapping a square causes that square to disappear.

What's the "best practices" way to set this up in Cocos2D?

Here's my plan so far:

  • One Objective-c GameState singleton class (maintains list of active squares)
  • One CCScene (since there's no menus etc)
  • One CCLayer (child node of the scene)
  • Many CCSprite nodes (one for each square, all child nodes of the layer)
  • Each sprite listens for a tap on itself. Receive tap => remove from GameState

Since I'm relatively new to Cocos2D I'd like some feedback on this design. For example I'm unsure of the GameState singleton. Perhaps it's unnecessary.

share|improve this question
up vote 2 down vote accepted

Looks good. But you don't really need a CCScene class. Just implementing the scene-method listed below in your CCLayer works fine. And the need to let the singleton maintain a list of active squares is indeed unnecessary, unless you have a good reason to keep it.

// Scene with layer method
+(CCScene*) scene {
    CCScene* scene = [CCScene node];
    MyLayer* layer = [MyLayer node];
    [scene addChild:layer];
    return scene;
share|improve this answer

the design seems good although I would not use the singleton but add the sprite as children of the layer and remove each sprite from its father when touched (this would also make it disappear). I guess this design is good to start but you will probably want to add some menu so you will have more scenes. In that case you can use the singleton to store the information you need among the different scene (i.e. score, etc.).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.