How to add a button

Hi,
I am new to cocos2d-x.
I would like to add a button to my game.
I want to add, is simply a button that opens the window (attached file) where I want to write a few lines of text.
The code that I have is bellow :

MainMenu.h

#ifndef __MAINMENU_H__
    #define __MAINMENU_H__
    #include "cocos2d.h"

    using namespace cocos2d;

class MainMenu : public cocos2d::CCLayer {
    cocos2d::CCSize s;

public:
    virtual bool init();
    virtual void playGame();
    static void mainMenu();
    static CCScene* scene();
    LAYER_CREATE_FUNC(MainMenu);
}; // __MAINMENU_H__


#endif

MainMenu.cpp

#include "MainMenu.h"
#include "SimpleAudioEngine.h"
#include "GameButton.h"
#include "Game.h"
#include "Utils.h"
#include "Constants.h"

using namespace cocos2d;
using namespace CocosDenshion;

//USING_NS_CC;

CCScene* MainMenu::scene()
{
    CCScene *sc = CCScene::create();
    MainMenu *m = MainMenu::create();
    sc->addChild(m, 0);
    return sc;
}

bool MainMenu::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }

    s = CCDirector::sharedDirector()->getWinSize();
    SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
    SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("moles_bg.mp3");
    SimpleAudioEngine::sharedEngine()->preloadEffect(SOUND_SPLAT);
    CCString* file = (Utils::getArtScaleFactor() > 1) ? CCString::create("moles-hd.plist") : CCString::create("moles.plist");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(file->getCString());

    file = (Utils::getArtScaleFactor() > 1) ? CCString::create("title-hd.png") : CCString::create("title.png");
    CCSprite *bg = CCSprite::create(file->getCString());
    bg->setPosition(ccp(s.width/2,s.height/2));
    Utils::scaleSprite(bg);
    this->addChild(bg,-1);

    CCMenuItemSprite *playButton = CCMenuItemSprite::create(GameButton::buttonWithText("PLAY!", true), NULL, this, menu_selector(MainMenu::playGame));
    CCMenu *menu = CCMenu::create(playButton,NULL);
    menu->setPosition(ccp(s.width/2,s.height/2 - s.height/3.5f));
    this->addChild(menu,2);

    return true;
}

void MainMenu::playGame()
{
    CCDirector::sharedDirector()->replaceScene(Game::scene());
}

void MainMenu::mainMenu()
{
    CCDirector::sharedDirector()->replaceScene(MainMenu::scene());
}

Does anyone could tell me what I have to add, that the prgrama show the window?
Appreciate any help.


menu.png (190.2 KB)

GameButton::buttonWithText(“PLAY!”, true)

This is AFAIK shortcut static method to create CCSprite with text in it. You don’t speaking of showing the title, so I assume “title.png” or “title-hd.png” are available and successfully painted at screen. If you try to change the line with default button sprite:
CCMenuItemSprite *playButton = CCMenuItemSprite::create(GameButton::buttonWithText("PLAY!", true), NULL, this, menu_selector(MainMenu::playGame));

to:

CCMenuItemSprite *playButton = CCMenuItemSprite::create("button.png", NULL, this, menu_selector(MainMenu::playGame));

after you put “button.png” in your Resource folder, and you can see that button, then the problem is in GameButton::buttonWithText static method which should return a sprite for default button behaviour (you put NULKL to “selected” state, you may try to replace NULL with “button1.png” to have selected behaviour).