本文整理汇总了C++中MenuItemSprite::setTag方法的典型用法代码示例。如果您正苦于以下问题:C++ MenuItemSprite::setTag方法的具体用法?C++ MenuItemSprite::setTag怎么用?C++ MenuItemSprite::setTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MenuItemSprite
的用法示例。
在下文中一共展示了MenuItemSprite::setTag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool ResultLayer::init()
{
if (!Layer::init())
{
return false;
}
//des
LabelTTF* labelDes = LabelTTF::create(PlayRound::shared()->getPrivityDescription(PlayRound::shared()->getLevel()), "黑体", FONTSIZE(25));
//LabelTTF* labelDes = LabelTTF::create(PlayRound::shared()->getPrivityDescription(0), "黑体", 30);
labelDes->setPosition(Point(COMWinSize().width/2,COMWinSize().height*0.9));
addChild(labelDes);
__String* strLevel = __String::createWithFormat("我到了第%d层啦!",PlayRound::shared()->getLevel());
LabelTTF* labelLevel = LabelTTF::create(strLevel->getCString(), "黑体", FONTSIZE(40));
labelLevel->setPosition(Point(COMWinSize().width/2,COMWinSize().height*0.8));
addChild(labelLevel);
Sprite* spNormal = Sprite::create("image/btn_restart.png");
Sprite* spSelect = Sprite::create("image/btn_restart.png");
// spNormal->setScale(960/COMWinSize().height);
// spSelect->setScale(960/COMWinSize().height);
spSelect->setColor(Color3B(200,200,200));
MenuItemSprite* itemSp = MenuItemSprite::create(spNormal, spSelect, CC_CALLBACK_1(ResultLayer::onClick, this));
//MenuItemLabel* label = MenuItemLabel::create(LabelTTF::create("重新开始", "黑体", 50),CC_CALLBACK_1(ResultLayer::onClick, this) );
itemSp->setTag(kResultRestartTag);
Menu* menu = Menu::create(itemSp, nullptr);
menu->setPosition(Point(COMWinSize().width/2,COMWinSize().height/2));
this->addChild(menu);
if (CCRANDOM_0_1()>0.8)
{
ShowYouAd::shared()->showYouWallSpot();
}
//Results.m4a
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sound/Results.m4a");
//历史分数
__String* strHistory;
int iHistory = UserDefault::getInstance()->getIntegerForKey("HistoryScore");
if (iHistory<PlayRound::shared()->getLevel()) {
iHistory = PlayRound::shared()->getLevel();
UserDefault::getInstance()->setIntegerForKey("HistoryScore", PlayRound::shared()->getLevel());
UserDefault::getInstance()->flush();
strHistory = __String::createWithFormat("打破记录啦:%d层!!!",iHistory);
}
else
{
strHistory = __String::createWithFormat("历史最高:%d层",iHistory);
}
LabelTTF* ttfHistory = LabelTTF::create(strHistory->getCString(), "黑体", FONTSIZE(50));
ttfHistory->setPosition(Point(COMWinSize().width/2,COMWinSize().height*0.7));
addChild(ttfHistory);
return true;
}
示例2: addButton
bool DialogLayer::addButton(const char* title, Sprite* normalImage, Sprite* selectedImage, Sprite* disableImage, const ccMenuCallback& callback, int tag/* =0 */)
{
Size winSize = Director::getInstance()->getWinSize();
Point pCenter = Point(winSize.width / 2, winSize.height / 2);
// 创建图片菜单按钮
MenuItemSprite* menuImage = MenuItemSprite::create(normalImage, selectedImage, disableImage, callback);
menuImage->setTag(tag);
menuImage->setPosition(pCenter);
// 添加文字说明并设置位置
Size imenu = menuImage->getContentSize();
LabelTTF* ttf = CCLabelTTF::create(title, "Arial", 25);
ttf->setColor(Color3B(0, 0, 0));
ttf->setPosition(imenu.width / 2, imenu.height / 2);
menuImage->addChild(ttf);
getMenuButton()->addChild(menuImage);
return true;
}
示例3: init
bool HomeLayer::init(){
bool isDay = UserDefault::getInstance()->getBoolForKey(DayTime, true);
string file = "modify/day_bg.png";
if (isDay == false) {
file = string("modify/night_bg.png");
}
if (GameLayerBase::initWithBgFileName(file.c_str())) {
Sprite* centerTitle = Sprite::create("modify/title.png");
centerTitle->setAnchorPoint(Vec2(0.5, 1.0));
centerTitle->setPosition(STVisibleRect::getCenterOfScene().x, STVisibleRect::getPointOfSceneLeftUp().y - 60);
addChild(centerTitle, 1);
//
// TableViewTest* pLayer = TableViewTest::create();
// this->addChild(pLayer, 2);
MenuItemSprite* lightBtn = CocosHelper::menuItemSprite("modify/night.png");
MenuItemSprite* settingBtn = CocosHelper::menuItemSprite("modify/setting.png");
MenuItemSprite* vedioBtn = CocosHelper::menuItemSprite("modify/video.png");
string soundFile = "modify/sound1.png";
if (!SoundPlayer::getInstance()->isMusicOpen()) {
soundFile = "modify/sound2.png";
}
MenuItemSprite* soundBtn = CocosHelper::menuItemSprite(soundFile.c_str());
MenuItemSprite* shareBtn = CocosHelper::menuItemSprite("modify/share.png");
lightBtn->setTag(kLightBtnTag);
settingBtn->setTag(kSettingBtnTag);
vedioBtn->setTag(kVedioBtnTag);
soundBtn->setTag(kSoundBtnTag);
shareBtn->setTag(kShareBtnTag);
lightBtn->setAnchorPoint(Vec2(0, 0));
settingBtn->setAnchorPoint(Vec2(1.0, 0));
vedioBtn->setAnchorPoint(Vec2(0.5, 0));
soundBtn->setAnchorPoint(Vec2(1.0, 0));
shareBtn->setAnchorPoint(Vec2(1.0, 0));
lightBtn->setPosition(Vec2(STVisibleRect::getOriginalPoint().x + 15, 60*0.618+STVisibleRect::getOriginalPoint().y));
settingBtn->setPosition(Vec2(STVisibleRect::getPointOfSceneRightBottom().x - 15, 60*0.618 + STVisibleRect::getOriginalPoint().y));
vedioBtn->setPosition(Vec2(STVisibleRect::getCenterOfScene().x, lightBtn->getBoundingBox().getMaxY() + 15));
soundBtn->setPosition(settingBtn->getPosition()+Vec2(15, 0));
shareBtn->setPosition(settingBtn->getPosition()+Vec2(15, 0));
lightBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
settingBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
vedioBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
Menu* pBtns = Menu::create(lightBtn, settingBtn, vedioBtn, NULL);
pBtns->setAnchorPoint(Vec2(0, 0));
pBtns->setPosition(Vec2(0, 0));
addChild(pBtns, 2);
float maxHeight = centerTitle->getBoundingBox().getMidY() - vedioBtn->getBoundingBox().getMaxY();
log("the max height is %.2f", maxHeight);
float tableHeight = maxHeight - 100*1.618;
float tableWidth = STVisibleRect::getGlvisibleSize().width - 200*0.618;
log("the tablewidth is %.2f, and the tableheight is %.2f", tableWidth, tableHeight);
int w = (int)tableWidth;
int h = (int)tableHeight;
TableViewTest* pLayer = TableViewTest::create(Size(w, h));
pLayer->setPosition(Vec2(100*0.618 + STVisibleRect::getOriginalPoint().x, vedioBtn->getBoundingBox().getMaxY() + 100*0.618));
addChild(pLayer, 10);
pLayer->setDelegate(this);
return true;
}
return false;
}