Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

2 Answers 2

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

 
discard

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.