本文整理汇总了C++中CCMenuItemLabel::initWithTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemLabel::initWithTarget方法的具体用法?C++ CCMenuItemLabel::initWithTarget怎么用?C++ CCMenuItemLabel::initWithTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemLabel
的用法示例。
在下文中一共展示了CCMenuItemLabel::initWithTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
// on "init" you need to initialize your instance
bool HelloWorld::init() {
//////////////////////////////
// 1. super init first
if (!CCLayer::init()) {
return false;
}
this->setKeypadEnabled(true);
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCSpriteFrameCache* pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
pCache->addSpriteFramesWithFile("buttons.plist", "buttons.png");
CCMenu* pMenu = CCMenu::create();
std::string uname = CCUserDefault::sharedUserDefault()->getStringForKey(
"UserName");
CCPoint position = ccp(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height * 0.9);
if (uname.empty()) {
//register or login
} else {
CCString *str = CCString::createWithFormat("用户:%s", uname.c_str());
CCLabelTTF *pName = CCLabelTTF::create(str->getCString(), "Arial.ttf",
60);
pName->setPosition(position);
pName->setColor(ccc3(0, 0, 0));
this->addChild(pName, 2);
}
CCSprite *pBtnSprite = CCSprite::createWithSpriteFrameName(
"button_large.png");
CCSize btnSize = pBtnSprite->getContentSize();
int padding = 15;
position = position - ccp(0, btnSize.height + padding);
pBtnSprite->setPosition(position);
this->addChild(pBtnSprite, 1);
CCLabelTTF * pLabel = CCLabelTTF::create("普通模式", "Arial.ttf",
btnSize.height * 0.6);
pLabel->setColor(ccc3(0, 0, 0));
CCMenuItemLabel *pPlayItem = CCMenuItemLabel::create(pLabel);
pPlayItem->setContentSize(btnSize);
pPlayItem->initWithTarget(this,
menu_selector(HelloWorld::menuPlayCallback));
pPlayItem->setPosition(position);
pMenu->addChild(pPlayItem);
position = position - ccp(0, btnSize.height + padding);
pBtnSprite = CCSprite::createWithSpriteFrameName("button_large.png");
pBtnSprite->setPosition(position);
this->addChild(pBtnSprite, 1);
pLabel = CCLabelTTF::create("继续游戏", "Arial.ttf", btnSize.height * 0.6);
pLabel->setColor(ccc3(0, 0, 0));
CCMenuItemLabel *pLoadItem = CCMenuItemLabel::create(pLabel);
pLoadItem->setContentSize(btnSize);
pLoadItem->initWithTarget(this,
menu_selector(HelloWorld::menuLoadCallback));
pLoadItem->setPosition(position);
pMenu->addChild(pLoadItem);
position = position - ccp(0, btnSize.height + padding);
pBtnSprite = CCSprite::createWithSpriteFrameName("button_large.png");
pBtnSprite->setPosition(position);
this->addChild(pBtnSprite, 1);
pLabel = CCLabelTTF::create("回放游戏", "Arial.ttf", btnSize.height * 0.6);
pLabel->setColor(ccc3(0, 0, 0));
CCMenuItemLabel *pReplayItem = CCMenuItemLabel::create(pLabel);
pReplayItem->setContentSize(btnSize);
pReplayItem->initWithTarget(this,
menu_selector(HelloWorld::menuReplayCallback));
pReplayItem->setPosition(position);
pMenu->addChild(pReplayItem);
position = position - ccp(0, btnSize.height + padding);
pBtnSprite = CCSprite::createWithSpriteFrameName("button_large.png");
pBtnSprite->setPosition(position);
this->addChild(pBtnSprite, 1);
pLabel = CCLabelTTF::create("竞赛模式", "Arial.ttf", btnSize.height * 0.6);
pLabel->setColor(ccc3(0, 0, 0));
CCMenuItemLabel *pCompetitionItem = CCMenuItemLabel::create(pLabel);
pCompetitionItem->setContentSize(btnSize);
pCompetitionItem->initWithTarget(this,
menu_selector(HelloWorld::menuCompetitionCallback));
pCompetitionItem->setPosition(position);
pMenu->addChild(pCompetitionItem);
position = position - ccp(0, btnSize.height + padding);
pBtnSprite = CCSprite::createWithSpriteFrameName("button_large.png");
pBtnSprite->setPosition(position);
this->addChild(pBtnSprite, 1);
pLabel = CCLabelTTF::create("编辑模式", "Arial.ttf", btnSize.height * 0.6);
pLabel->setColor(ccc3(0, 0, 0));
CCMenuItemLabel *pEditItem = CCMenuItemLabel::create(pLabel);
pEditItem->setContentSize(btnSize);
pEditItem->initWithTarget(this,
menu_selector(HelloWorld::menuEditCallback));
pEditItem->setPosition(position);
pMenu->addChild(pEditItem);
//.........这里部分代码省略.........