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.


2 Answers 2


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;

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.).


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .