cocos2d ccmenulabel

时间:2023-12-19 13:20:02
//
// TestMenu.hpp
// mario
//
// Created by sun on 15/12/22.
//
// #ifndef TestMenu_hpp
#define TestMenu_hpp #include <stdio.h>
#include "cocos2d.h"
USING_NS_CC;
using namespace std;
class TestMenu : public CCLayer
{
public:
virtual bool init();
static CCScene* scene();
CREATE_FUNC(TestMenu);
void menuCloseCallback(CCObject* pSender);
}; #endif /* TestMenu_hpp */
//
// TestMenu.cpp
// mario
//
// Created by sun on 15/12/22.
//
// #include "TestMenu.hpp" CCScene* TestMenu::scene()
{
CCScene *scene = CCScene::create();
TestMenu *layer = TestMenu::create();
scene->addChild(layer);
return scene;
} bool TestMenu::init()
{ if ( !CCLayer::init() )
{
return false;
} CCSize winsize=CCDirector::sharedDirector()->getWinSize(); CCLabelTTF *label=CCLabelTTF::create("显示精灵","Thonburi", 48); CCMenuItemLabel *item=CCMenuItemLabel::create(label,this, menu_selector(TestMenu::menuCloseCallback));
item->setPosition(ccp(winsize.width/2,
winsize.height/2)); CCMenu* pMenu = CCMenu::create(item, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1); return true;
} void TestMenu::menuCloseCallback(CCObject* pSender)
{
CCLOG("dianying");
}