Search code examples
objective-ccocos2d-iphoneflappy-bird-clone

Game over pop-up like Flappy Bird


How can I make a game over pop-up like Flappy Bird in cocos2d-iphone 3?

enter image description here

I tried to add a new Scene, but it adds a new screen on the game, I just want a rectangle with some buttons inside it. I also search how to add multiple scene, but didn't find an example doing it.


Solution

  • You want to use a CCNode. Create your own class - GameOverNode which subclasses CCNode, then you want to add buttons and your images to this GameOverNode.

    When you need to create the GameOverNode and show it to the user, you simply initialise it and add it to your CCScene.

    Edit: Changed CCLayer to CCNode as per changes in the cocos2Diphone documentation - http://www.cocos2d-iphone.org/api-ref/3.0-rc1/Classes/CCScene.html

    @interface GameOverNode : CCNode {
        CCButton *_aButton;
        CCSprite *_aSprite;
        CCLabelTTF *_aLabel;
    }
    
    @property (nonatomic, retain) CCButton *aButton;
    @property (nonatomic, retain) CCSprite *aSprite;
    @property (nonatomic, retain) CCLabelTTF *aLabel;
    
    @end
    

    Then inside the implementation of your GameOverNode:

    @implementation GameOverNode
    
    
    -(id)init {
        if ( self = [super init] ){
            //initialise your buttons, labels, sprites
            //add them to your node
        }
        return self;
    }
    
    @end
    

    Finally in your CCScene. Initialise your GameOverNode and add it to the scene

     GameOverNode *gameOverNode = [GameOverNode alloc];
     [gameOverNode init];
     [self addChild:gameOverNode];