本文整理汇总了C++中CCMenuItemLabel类的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemLabel类的具体用法?C++ CCMenuItemLabel怎么用?C++ CCMenuItemLabel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCMenuItemLabel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: menu_selector
// on "init" you need to initialize your instance
bool TitleScene::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
//add the menu item for back to main menu
int contentHeight = 0;
int contentWidth = 0;
m_pItemMenu = CCMenu::create();
for (int i = 0; i < ITEM_COUNT; ++i)
{
CCLabelTTF* label = CCLabelTTF::create(menuItem[i].c_str(), "Arial", VisibleRect::getScaledFont(20));
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(TitleScene::menuCallback));
pMenuItem->setAnchorPoint(CCPointZero);
contentHeight = MAX(contentHeight, pMenuItem->getContentSize().height);
contentWidth = MAX(contentWidth, pMenuItem->getContentSize().width);
CCLog("Height = %d", contentHeight);
CCLog("Width = %d", contentWidth);
m_pItemMenu->addChild(pMenuItem, i + 10000);
}
m_pItemMenu->setContentSize(CCSizeMake(contentWidth, (ITEM_COUNT - 1) * contentHeight));
m_pItemMenu->setPosition(ccp( CCDirector::sharedDirector()->getWinSize().width - m_pItemMenu->getContentSize().width, m_pItemMenu->getContentSize().height));
m_pItemMenu->alignItemsVertically();
this->addChild(m_pItemMenu, 1);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
// CCLabelTTF* pLabel = CCLabelTTF::create("Title Scene", "Thonburi", VisibleRect::getScaledFont(34));
//
// // ask director the window size
// CCSize size = VisibleRect::getVisibleRect().size;
//
// // position the label on the center of the screen
// pLabel->setPosition( ccp(size.width / 2, size.height - VisibleRect::getScaledFont(20)) );
//
// // add the label as a child to this layer
// this->addChild(pLabel, 1);
// add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::create("Default.png");
pSprite->setScale(VisibleRect::getScale());
// position the sprite on the center of the screen
pSprite->setPosition( ccp(VisibleRect::getVisibleRect().size.width/2, VisibleRect::getVisibleRect().size.height/2) );
// add the sprite as a child to this layer
this->addChild(pSprite, 0);
return true;
}
示例2: menu_selector
void BYGameScene::loadUI() {
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
frameCache->addSpriteFramesWithFile("ui.plist", "ui.png");
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
/// pause button
CCSprite* btnNormalSprite = CCSprite::createWithSpriteFrameName("pause.png");
CCMenuItemSprite *pauseMenuItem = CCMenuItemSprite::create(btnNormalSprite,
btnNormalSprite,
this,
menu_selector(BYGameScene::pauseButtonHandler));
/// 2 labels for goals
ccColor3B color = ccc3(220, 70, 20); /// red color
_labelBotPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40);
_labelBotPlayerGoalsScored->setColor(color);
CCMenuItemLabel *labelBot = CCMenuItemLabel::create(_labelBotPlayerGoalsScored, NULL, NULL);
labelBot->setEnabled(false);
_labelTopPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40);
_labelTopPlayerGoalsScored->setColor(color);
CCMenuItemLabel *labelTop = CCMenuItemLabel::create(_labelTopPlayerGoalsScored, NULL, NULL);
labelTop->setEnabled(false);
/// CCMenu doesnt support anchorPoint as of 0x00020003 version
CCMenu *menu = CCMenu::create(labelTop, pauseMenuItem, labelBot, NULL);
menu->alignItemsHorizontallyWithPadding(5);
menu->setAnchorPoint(CCPointMake(0, 0));
menu->setPosition(CCPointMake(winSize.width - pauseMenuItem->getContentSize().width / 2,
winSize.height / 2));
menu->setRotation(90);
this->addChild(menu);
}
示例3: addChild
// on "init" you need to initialize your instance
bool AboutScene::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
//背景图片 start
CCSprite* pSprite = CCSprite::create("about.png");
float winw = visibleSize.width; //获取屏幕宽度
float winh = visibleSize.height;//获取屏幕高度
float spx = pSprite->getTextureRect().getMaxX();
float spy = pSprite->getTextureRect().getMaxY();
// add the sprite as a child to this layer
float scaleX = winw/spx;
float scaleY = winh/spy;
pSprite->setScaleX(scaleX);
pSprite->setScaleY(scaleY);
// position the sprite on the center of the screen
pSprite->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
addChild(pSprite,0);
CCLabelTTF* backlabel = CCLabelTTF::create("返回", "AR PLMingU20 Light", 24);
backlabel->setColor(ccc3(0,0,0));
CCMenuItemLabel *back = CCMenuItemLabel::create(backlabel,this,menu_selector(AboutScene::backCallback));
back->setPosition(300,-visibleSize.height/2+50);
CCMenu * menu = CCMenu::create(back,NULL);
this->addChild(menu,2);
return true;
}
示例4: m_tBeginPos
TestController::TestController()
: m_tBeginPos(0, 0)
, m_pItemMenu(NULL)
{
// add close menu
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(s_pPathClose, s_pPathCloseSelected, this, menu_selector(TestController::closeCallback));
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
pCloseItem->setPosition(ccp(VisibleRect::right().x - 30 , VisibleRect::top().y - 30));
addChild(pMenu, 1);
//add menu ites for tests
m_pItemMenu = CCMenu::create();
for (int i=0; i < TESTS_COUNT; i++) {
//add the menu item for back to main menu
//#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
//CCLabelBMFont* label = CCLabelBMFont::create("MainMenu", "fonts/arial16.fnt");
//#else
CCLabelTTF* label = CCLabelTTF::create(g_aTestNames[i].c_str(), "Arial", 24);
//#endif
CCMenuItemLabel* pMenuItemLabel = CCMenuItemLabel::create(label, this, menu_selector(TestController::menuCallback));
m_pItemMenu->addChild(pMenuItemLabel, 0, i + 10000);
pMenuItemLabel->setPosition(ccp(VisibleRect::center().x, (VisibleRect::top().y - (i+1) * LINE_SPACE )));
}
m_pItemMenu->setContentSize(CCSizeMake(VisibleRect::getVisibleRect().size.width, (TESTS_COUNT + 1) * LINE_SPACE));
m_pItemMenu->setPosition(s_tCurPos);
addChild(m_pItemMenu);
//这里有个坑,使用create方法,必须从写init方法,并且设置m_bTouchEnabled=true,从能滚动
//若外部使用new的方式,这里设置true就可以滚动。
setTouchEnabled(true);
}
示例5: CCMenuItemLabel
CCMenuItemLabel * CCMenuItemLabel::create(CCNode*label, CCObject* target, SEL_MenuHandler selector)
{
CCMenuItemLabel *pRet = new CCMenuItemLabel();
pRet->initWithLabel(label, target, selector);
pRet->autorelease();
return pRet;
}
示例6: CCMenuItemLabel
CCMenuItemLabel * CCMenuItemLabel::itemWithLabel(CCNode*label, SelectorProtocol* target, SEL_MenuHandler selector)
{
CCMenuItemLabel *pRet = new CCMenuItemLabel();
pRet->initWithLabel(label, target, selector);
pRet->autorelease();
return pRet;
}
示例7: ccp
// on "init" you need to initialize your instance
bool MissionLayer::init() {
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() ) {
return false;
}
this->setKeypadEnabled(true);
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* title = CCLabelTTF::create("Mission", "Arial", 24);
title->setPosition( ccp(size.width / 2, size.height - 20));
this->addChild(title, 1);
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"b1.png",
"b2.png",
this,
menu_selector(MissionLayer::menuBackCallback) );
pCloseItem->setPosition( ccp(pCloseItem->getContentSize().width / 2 , 20) );
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
// add next menu
CCMenuItemImage *pNextItem = CCMenuItemImage::create(
"f1.png",
"f2.png",
this,
menu_selector(MissionLayer::menuNextCallback) );
pNextItem->setPosition( ccp(size.width - pNextItem->getContentSize().width / 2, 20) );
// create menu, it's an autorelease object
CCMenu* pNextMenu = CCMenu::create(pNextItem, NULL);
pNextMenu->setPosition( CCPointZero );
this->addChild(pNextMenu, 1);
float step = 35;
float yPos = 0;
for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
char buf[64];
sprintf(buf, s_EventMenuItem[i].id.c_str(), missionid);
CCLabelTTF* label = CCLabelTTF::create(buf, "Arial", 24);
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MissionLayer::eventMenuCallback));
pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);
yPos = size.height - step*i - 100;
pMenuItem->setPosition( ccp(size.width / 2, yPos));
}
return true;
}
示例8: CC_BREAK_IF
// on "init" you need to initialize your instance
bool StartLayer::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF *label = CCLabelTTF::create("New Game", "Arial", 24 * 2);
CCMenuItemLabel *pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(StartLayer::menuNewGameCallback));
pMenuItem->setTag(1);
pMenuItem->setPosition(winSize.width / 2, winSize.height / 2);
CCMenu* pMenu = CCMenu::create(pMenuItem, NULL);
pMenu->setPosition(CCPointZero);
CC_BREAK_IF(! pMenu);
this->addChild(pMenu, 1);
CCLabelTTF* pLabel = CCLabelTTF::create("Bubble Cat 2014", "Arial", 24 * 3);
CC_BREAK_IF(! pLabel);
pLabel->setPosition(ccp(winSize.width / 2, winSize.height - 50));
this->addChild(pLabel, 1);
CCSprite* pSprite = CCSprite::create("StartScene_CN.jpg");
CC_BREAK_IF(! pSprite);
pSprite->setPosition(ccp(winSize.width/2, winSize.height/2));
this->addChild(pSprite, 0);
bRet = true;
} while (0);
return bRet;
}
示例9: eventMenuCallback
void VirtualCurrencyLayer::eventMenuCallback(CCObject* pSender) {
CCMenuItemLabel* pMenuItem = (CCMenuItemLabel*)pSender;
int i = pMenuItem->getTag();
EventParamMap paramMap;
pthread_t thread;
switch (i) {
case ONREQUEST:
TDCCVirtualCurrency::onChargeRequest("o_1", "iap", 10, "CN", 20, "T1");
break;
case ONSUCCESS:
pthread_create(&thread, NULL, runThread, NULL);
break;
case ONREWARD:
TDCCVirtualCurrency::onReward(100, "reason");
break;
case ONEVENT:
paramMap.insert(EventParamPair("type", "popular"));
paramMap.insert(EventParamPair("artist", "JJLin"));
paramMap["aa"] = "bb";
TDCCTalkingDataGA::onEvent("music", ¶mMap);
break;
default:
break;
}
}
示例10: menu_selector
bool MapEditLayer::init()
{
this->setTouchEnabled(true);
CCLabelTTF* label = CCLabelTTF::create(str_back, "", 20);
CCMenuItemLabel* labelItem = CCMenuItemLabel::create(label, this, menu_selector(MapEditLayer::back));
labelItem->setPosition(ccp(135,-200));
TMenuItem *item1 = TMenuItem::create(1, 1, 1,this, menu_selector(MapEditLayer::menuSelect));
item1->setPosition(ccp(-100, 180));
TMenuItem *item2 = TMenuItem::create(2, 2, 1,this, menu_selector(MapEditLayer::menuSelect));
item2->setPosition(ccp(-50, 180));
TMenuItem *item3 = TMenuItem::create(3, 3, 1,this, menu_selector(MapEditLayer::menuSelect));
item3->setPosition(ccp(0, 180));
TMenuItem *item4 = TMenuItem::create(4, 2, 2,this, menu_selector(MapEditLayer::menuSelect));
item4->setPosition(ccp(50, 180));
TMenuItem *item5 = TMenuItem::create(5, 1, 3,this, menu_selector(MapEditLayer::menuSelect));
item5->setPosition(ccp(100, 180));
CCMenu *menu = CCMenu::create(item1, item2, item3, item4, item5,labelItem, NULL);
this->addChild(menu);
return true;
}
示例11: m_tBeginPos
//--------------------------------------------------------
CListControllerLayer::CListControllerLayer()
: m_tBeginPos( CCPointZero )
{
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(s_szCloseBtnImagePath, s_szCloseBtnImagePath, this, menu_selector(CListControllerLayer::closeCallback) );
CCMenu* pMenu =CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
pCloseItem->setPosition(ccp( CVisibleRect::right().x - 50, CVisibleRect::bottom().y + 50));
m_pItemMenu = CCMenu::create();
for (int i = 0; i < static_cast<int>(eTestSceneType_Max); ++i)
{
CCLabelTTF* label = CCLabelTTF::create( FKCW_Base_StringConvert::a2u( g_aTestNames[i].c_str() ).c_str(), "Arial", 32);
label->setColor( _GetColorByName(g_aTestNames[i]) );
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(CListControllerLayer::menuCallback));
m_pItemMenu->addChild(pMenuItem, i + 10000);
pMenuItem->setPosition( ccp( CVisibleRect::center().x, (CVisibleRect::top().y - (i + 1) * TEST_MENU_LINE_SPACE) ));
}
m_pItemMenu->setContentSize(CCSizeMake(CVisibleRect::getVisibleRect().size.width, (static_cast<int>(eTestSceneType_Max) + 1) * (TEST_MENU_LINE_SPACE)));
m_pItemMenu->setPosition(s_tCurPos);
addChild(m_pItemMenu);
setTouchEnabled(true);
addChild(pMenu, 1);
FKCOLORLOG( eConsolTextColor_Blue | eConsolBKColor_Yellow, "创建ListControllerLayer成功" );
}
示例12: m_tBeginPos
TestController::TestController()
: m_tBeginPos(CCPointZero)
{
// add close menu
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(s_pPathClose, s_pPathClose, this, menu_selector(TestController::closeCallback) );
CCMenu* pMenu =CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
pCloseItem->setPosition(ccp( VisibleRect::right().x - 30, VisibleRect::top().y - 30));
// add menu items for tests
m_pItemMenu = CCMenu::create();
for (int i = 0; i < TESTS_COUNT; ++i)
{
// #if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
// CCLabelBMFont* label = CCLabelBMFont::create(g_aTestNames[i].c_str(), "fonts/arial16.fnt");
// #else
CCLabelTTF* label = CCLabelTTF::create(g_aTestNames[i].c_str(), "Arial", 24);
// #endif
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(TestController::menuCallback));
m_pItemMenu->addChild(pMenuItem, i + 10000);
pMenuItem->setPosition( ccp( VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE) ));
}
m_pItemMenu->setContentSize(CCSizeMake(VisibleRect::getVisibleRect().size.width, (TESTS_COUNT + 1) * (LINE_SPACE)));
m_pItemMenu->setPosition(s_tCurPos);
addChild(m_pItemMenu);
setTouchEnabled(true);
addChild(pMenu, 1);
}
示例13: setBackgroundImage
void AboutLayer::setupViews(){
setBackgroundImage( "loading.png" );
// 加入title
CCSprite* title = CCSprite::create( "menuTitle.png",CCRectMake(0, 34, 130, 38) );
title->setAnchorPoint( ccp(0.5, 1) );
title->setPosition( ccp( getWinSize().width / 2 ,getWinSize().height -20 ) );
this->addChild( title );
// 加入文字说明
CCLabelBMFont* pDes = CCLabelBMFont::create( "This Game is recoded by longlingxiu ", "arial-14.fnt" );
pDes->setPosition( ccp(getWinSize().width / 2, getWinSize().height / 2) );
this ->addChild(pDes);
CCLabelBMFont* fontOfBack = CCLabelBMFont::create("Go Back", "arial-14.fnt" );
fontOfBack->setScale(1.5f);
CCMenuItemLabel* backLabel = CCMenuItemLabel::create(fontOfBack, this, menu_selector(AboutLayer::back_callback));
backLabel->setAnchorPoint( ccp( 0.5, 0 ) );
backLabel->setPosition( ccp( getWinSize().width / 2, 30) );
CCMenu* menu = CCMenu::create( backLabel, NULL );;
menu->setPosition( CCPointZero );
this->addChild( menu );
}
示例14: menu_selector
void ConfigMenu::makeMenu(){
CCMenuItemFont::setFontSize(50);
CCMenuItemFont::setFontName("Arial");
//CCMenuItemToggle* music = CCMenuItemToggle::createWithTarget(this, menu_selector(ConfigMenu::musicMenuCallback),
//CCMenuItemFont::create("Music OFF"),
//CCMenuItemFont::create("Music ON"), NULL);
CCMenuItemToggle* music = CCMenuItemToggle::createWithTarget(this, menu_selector(ConfigMenu::musicMenuCallback),
CCMenuItemLabel::create(CCLabelBMFont::create("Music OFF", "arial-unicode-26.fnt", 300)),
CCMenuItemLabel::create(CCLabelBMFont::create("Music ON", "arial-unicode-26.fnt", 300)), NULL);
CCLabelBMFont* txtShare = CCLabelBMFont::create("Share", "arial-unicode-26.fnt", 300);
//CCMenuItemFont* share = CCMenuItemFont::create("Share", this, menu_selector(ConfigMenu::shareMenuCallback));
//CCLabelTTF* d = CCLabelTTF::create("Share", "Arial", 30);
CCMenuItemLabel* share = CCMenuItemLabel::create(txtShare, this, menu_selector(ConfigMenu::shareMenuCallback));
music->setPosition(ccp(0,-60));
share->setPosition(ccp(0, music->getContentSize().height+music->getPositionY()+20));
share->setScale(2);
music->setScale(2);
CCMenu *menu = CCMenu::create(music, share, NULL);
//menu->setPosition(ccp(400,0));
menu->setOpacity(kCCMenuHandlerPriority);
this->addChild(menu);
if(!CCUserDefault::sharedUserDefault()->getBoolForKey(CONFIG_KEY_HAS_MUSIC)){
music->setSelectedIndex(1);
}else{
music->setSelectedIndex(0);
}
}
示例15: m_pItmeMenu
CocosDenshionTest::CocosDenshionTest()
: m_pItmeMenu(NULL),
m_tBeginPos(CCPointZero),
m_nSoundId(0)
{
std::string testItems[] = {
"play background music",
"stop background music",
"pause background music",
"resume background music",
"rewind background music",
"is background music playing",
"play effect",
"play effect repeatly",
"stop effect",
"unload effect",
"add background music volume",
"sub background music volume",
"add effects volume",
"sub effects volume",
"pause effect",
"resume effect",
"pause all effects",
"resume all effects",
"stop all effects"
};
// add menu items for tests
m_pItmeMenu = CCMenu::create();
CCSize s = CCDirector::sharedDirector()->getWinSize();
m_nTestCount = sizeof(testItems) / sizeof(testItems[0]);
for (int i = 0; i < m_nTestCount; ++i)
{
//#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
// CCLabelBMFont* label = CCLabelBMFont::create(testItems[i].c_str(), "fonts/arial16.fnt");
//#else
CCLabelTTF* label = CCLabelTTF::create(testItems[i].c_str(), "Arial", 24);
//#endif
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(CocosDenshionTest::menuCallback));
m_pItmeMenu->addChild(pMenuItem, i + 10000);
pMenuItem->setPosition( CCPointMake( s.width / 2, (s.height - (i + 1) * LINE_SPACE) ));
}
m_pItmeMenu->setContentSize(CCSizeMake(s.width, (m_nTestCount + 1) * LINE_SPACE));
m_pItmeMenu->setPosition(CCPointZero);
addChild(m_pItmeMenu);
setTouchEnabled(true);
// preload background music and effect
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE) );
SimpleAudioEngine::sharedEngine()->preloadEffect( CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE) );
// set default volume
SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
}