本文整理汇总了C++中CCMenuItem::setTag方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItem::setTag方法的具体用法?C++ CCMenuItem::setTag怎么用?C++ CCMenuItem::setTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItem
的用法示例。
在下文中一共展示了CCMenuItem::setTag方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool CChooseLetterWindow::init()
{
m_Back = Sprite::create("choose_letter.png");
m_Back->setPosition(600,384);
m_Back->setVisible(false);
addChild(m_Back);
std::vector<char> m_Letters;
m_Letters.resize(26);
m_Letters[0] = 'a'; m_Letters[1] = 'b'; m_Letters[2] = 'c'; m_Letters[3] = 'd'; m_Letters[4] = 'e'; m_Letters[5] = 'f'; m_Letters[6] = 'g';
m_Letters[7] = 'h'; m_Letters[8] = 'i'; m_Letters[9] = 'j'; m_Letters[10] = 'k'; m_Letters[11] = 'l'; m_Letters[12] = 'm'; m_Letters[13] = 'n';
m_Letters[14] = 'o'; m_Letters[15] = 'p'; m_Letters[16] = 'q'; m_Letters[17] = 'r'; m_Letters[18] = 's'; m_Letters[19] = 't'; m_Letters[20] = 'u';
m_Letters[21] = 'v'; m_Letters[22] = 'w'; m_Letters[23] = 'x'; m_Letters[24] = 'y'; m_Letters[25] = 'z';
float startPosX = -460.0f;
float startPosY = -150.0f;
float stepX = 45.0f;
float stepY = 45.0f;
int columnCount = 6;
int rowCount = 4;
int id = 0;
int currentColumn = 0;
int currentRow = 0;
m_pMenu = CCMenu::create();
for(int i=0;i<m_Letters.size();i++)
{
Point pos = Point(startPosX+(currentColumn*stepX),startPosY+(-currentRow*stepY));
CCMenuItem * button = CCMenuItemImage::create(
"base.png",
"fixed.png",
this,
menu_selector(CChooseLetterWindow::LetterBtnClick));
button->setTag(int(m_Letters[i]));
button->setScale(0.35f);
button->setPosition(pos);
LabelTTF * letterLabel = LabelTTF::create("0","helvetica",82);
letterLabel->setPosition(button->getContentSize().width/2,button->getContentSize().height/2);
letterLabel->setColor(Color3B(0,0,0));
std::string str = "A";
str[0] = m_Letters[i];
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
letterLabel->setString(str);
button->addChild(letterLabel);
//letterLabel->setPosition(pos);
currentColumn++;
if(currentColumn == columnCount)
{
currentColumn = 0;
currentRow++;
}
m_pMenu->addChild(button);
m_pMenu->setEnabled(false);
}
m_Back->addChild(m_pMenu);
return true;
}
示例2: init
bool ControlLayer::init()
{
if(!CCLayer::init())
{
return false;
}
//创建方向按钮
CCMenuItem *up = CCMenuItemFont::itemWithString("up", this, menu_selector(ControlLayer::menuCallBackMove));
CCMenuItem *down = CCMenuItemFont::itemWithString("down", this, menu_selector(ControlLayer::menuCallBackMove));
CCMenuItem *left = CCMenuItemFont::itemWithString("left", this, menu_selector(ControlLayer::menuCallBackMove));
CCMenuItem *right = CCMenuItemFont::itemWithString("right", this, menu_selector(ControlLayer::menuCallBackMove));
up->setTag(kUp);
down->setTag(kDown);
left->setTag(kLeft);
right->setTag(kRight);
CCMenu *menu = CCMenu::menuWithItems(up, down, left, right, NULL);
//排列按钮
menu->alignItemsHorizontallyWithPadding(50);
this->addChild(menu);
return true;
}
示例3: addLabel
void DropDownListSprite:: addLabel(CCLabelTTF * label)
{
CCSize size = getContentSize();
CCLayerColor * normal = CCLayerColor::create(DROPDOWNLIST_NORMAL_COLOR,size.width,size.height);
CCLayerColor * selected = CCLayerColor::create(DROPDOWNLIST_SELECTED_COLOR, size.width, size.height);
m_bgLayers.push_back(normal);
m_selectLabels.push_back(label);
CCMenuItem * item = CCMenuItemSprite::create(normal, selected, NULL,this, SEL_MenuHandler(&DropDownListSprite::onSelected));
label->setPosition(ccp(size.width/2, size.height/2));
item->addChild(label);
item->setTag((int)m_selectLabels.size()-1);
item->setPosition(ccp(0,- (int)m_selectLabels.size() * size.height));
m_mainMenu->addChild(item);
}
示例4: init
bool SelectLevelScene::init(){
if(!CCScene::init()){
return false;
}
CCSprite* bg = CCSprite::create(Images::game::game_bg_jpg);
addChild(bg, -1);
bg->setAnchorPoint(ccp(0, 0));
CCMenu* menu = CCMenu::create();
addChild(menu, 1);
menu->setAnchorPoint(ccp(0, 0));
menu->setPosition(ccp(0, 0));
CCMenuItem* backItem = UIUtil::getSingleImageBtn(
Images::common::back);
menu->addChild(backItem);
backItem->setTarget(this, menu_selector(SelectLevelScene::onClickBtn));
backItem->setTag(-1);
backItem->setAnchorPoint(ccp(1, 0));
LayoutUtil::layoutTo(backItem, 0, 1, bg, 0, 1, 4, -4);
_stageImg = CCSprite::create(Images::selectLevel::level1);
_stageClickedImg = CCSprite::create(Images::selectLevel::level1);
_stageClickedImgMask = CCSprite::create(Images::selectLevel::level1);
_stageClickedImgMask->setColor(ccBLACK);
_stageClickedImgMask->setOpacity(80);
_stageClickedImg->addChild(_stageClickedImgMask, 1);
LayoutUtil::layoutToParentCenter(_stageClickedImgMask, _stageClickedImg);
CCMenuItem* stageItem = CCMenuItemSprite::create(_stageImg, _stageClickedImg);
stageItem->setTarget(this, menu_selector(SelectLevelScene::onClickBtn));
stageItem->setScale(1.3);
stageItem->setTag(1);
menu->addChild(stageItem);
LayoutUtil::layoutToParentCenter(stageItem, this);
CCMenuItem* leftArrow = UIUtil::getSingleImageBtn(Images::selectLevel::icon_arrow);
leftArrow->setTarget(this, menu_selector(SelectLevelScene::prev));
menu->addChild(leftArrow);
LayoutUtil::layoutTo(leftArrow, 1, 0.5, stageItem, 0, 0.5, -18);
CCSprite* leftArrowBg = CCSprite::create(Images::selectLevel::icon_arrow);
leftArrowBg->setScale(1.1);
leftArrowBg->setColor(ccBLACK);
addChild(leftArrowBg, 0);
LayoutUtil::layoutToCenter(leftArrowBg, leftArrow);
CCMenuItem* rightArrow = UIUtil::getSingleImageBtn(Images::selectLevel::icon_arrow);
rightArrow->setTarget(this, menu_selector(SelectLevelScene::next));
menu->addChild(rightArrow);
rightArrow->setScaleX(-1);
LayoutUtil::layoutTo(rightArrow, 0, 0.5, stageItem, 1, 0.5, 18);
CCSprite* rightArrowBg = CCSprite::create(Images::selectLevel::icon_arrow);
rightArrowBg->setScaleX(-1.1);
rightArrowBg->setScaleY(1.1);
rightArrowBg->setColor(ccBLACK);
addChild(rightArrowBg, 0);
LayoutUtil::layoutToCenter(rightArrowBg, rightArrow);
_stageIndexText = CCLabelTTF::create("01/11", "arial-bold", 30);
_stageIndexText->setColor(ccBLACK);
addChild(_stageIndexText, 1);
LayoutUtil::layoutTo(_stageIndexText, 0.5, 0, stageItem, 0.5, 1, 0, -20);
CCLabelTTF* title = CCLabelTTF::create("选择难度", "arial-bold", 38);
title->setColor(ccBLACK);
addChild(title, 1);
LayoutUtil::layoutTo(title, 0.5, 0, _stageIndexText, 0.5, 1, 0, 20);
MusicBtn* musicBtn = MusicBtn::create();
addChild(musicBtn, 1);
LayoutUtil::layoutTo(musicBtn, 0, 0, bg, 0, 0, 5, 5);
_curLevel = 0;
AdUtil::showAd();
return true;
}
示例5: CCDirectorGetWindowsSize
bool
MCSkillLayer::init()
{
if (MCBaseInfoLayer::init()) {
CCSize winSize = CCDirectorGetWindowsSize();
float contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
CCMenu *menu;
CCLabelTTF *label;
CCMenuItem *menuItem;
float fontSize = 24.0f / contentScaleFactor;
float offsetXLeft = 200 / contentScaleFactor;
content_.push_back(JsonBox::Value("name"));
content_.push_back(JsonBox::Value("releaseTime"));
content_.push_back(JsonBox::Value("activeTime"));
content_.push_back(JsonBox::Value("coldTime"));
content_.push_back(JsonBox::Value("consume"));
content_.push_back(JsonBox::Value("requiredProficiency"));
content_.push_back(JsonBox::Value("revise"));
content_.push_back(JsonBox::Value("count"));
content_.push_back(JsonBox::Value("effect"));
selectedSkill_ = NULL;
/* 技能种类 */
menu = CCMenu::create();
label = CCLabelTTF::create("剑", "", fontSize);
menuItem = CCMenuItemLabel::create(label,
this,
menu_selector(MCSkillLayer::selectSkillType));
menuItem->setTag(MCSwordSkill);
menu->addChild(menuItem);
label = CCLabelTTF::create("锤", "", fontSize);
menuItem = CCMenuItemLabel::create(label,
this,
menu_selector(MCSkillLayer::selectSkillType));
menuItem->setTag(MCHammerSkill);
menu->addChild(menuItem);
label = CCLabelTTF::create("斧", "", fontSize);
menuItem = CCMenuItemLabel::create(label,
this,
menu_selector(MCSkillLayer::selectSkillType));
menuItem->setTag(MCAxeSkill);
menu->addChild(menuItem);
label = CCLabelTTF::create("枪", "", fontSize);
menuItem = CCMenuItemLabel::create(label,
this,
menu_selector(MCSkillLayer::selectSkillType));
menuItem->setTag(MCSpearSkill);
menu->addChild(menuItem);
label = CCLabelTTF::create("弓", "", fontSize);
menuItem = CCMenuItemLabel::create(label,
this,
menu_selector(MCSkillLayer::selectSkillType));
menuItem->setTag(MCBowSkill);
menu->addChild(menuItem);
menu->alignItemsVerticallyWithPadding(4);
addChild(menu);
menu->setAnchorPoint(ccp(0, 0.5));
menu->setPosition(ccp(offsetXLeft, winSize.height / 2));
/* 技能表格 */
tableViewSize_ = CCSizeMake(180 / contentScaleFactor,
320 / contentScaleFactor);
tableView_ = CCTableView::create(this, tableViewSize_);
addChild(tableView_);
tableView_->setDirection(kCCScrollViewDirectionVertical);
tableView_->setDelegate(this);
tableView_->setVerticalFillOrder(kCCTableViewFillTopDown);
tableView_->setAnchorPoint(ccp(0, 0.5));
tableView_->setPosition(ccp(menu->getPositionX() + menuItem->getContentSize().width,
(winSize.height - tableViewSize_.height) / 2));
contentTableView_ = CCTableView::create(this, tableViewSize_);
addChild(contentTableView_);
contentTableView_->setDirection(kCCScrollViewDirectionVertical);
contentTableView_->setDelegate(this);
contentTableView_->setVerticalFillOrder(kCCTableViewFillTopDown);
contentTableView_->setAnchorPoint(ccp(0, 0.5));
contentTableView_->setPosition(ccp(tableView_->getPositionX() + tableViewSize_.width,
(winSize.height - tableViewSize_.height) / 2));
contentTableView_->setVisible(false);
icon_ = CCSprite::create();
addChild(icon_);
icon_->setAnchorPoint(ccp(1, 1));
icon_->setPosition(ccp(winSize.width - 64.0f / contentScaleFactor,
//.........这里部分代码省略.........
示例6: init
bool CSLayerPopupMsg::init(POPUPMSG_ENUM popEnum, string strTitle, string strMessage)
{
m_strMessage = strMessage;
m_strTitle = strTitle;
m_popEnum = popEnum;
CCSize size = CCDirector::sharedDirector()->getWinSize();
//添加背景
CCSprite *pSprite = CCSprite::spriteWithSpriteFrameName(m_strBackground.c_str());
pSprite->setPosition(ccp(size.width/2, size.height/2));
addChild(pSprite);
//标题栏
CCLabelTTF *pLabel = CCLabelTTF::labelWithString(m_strTitle.c_str(), "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(size.width*2/5, size.height*7/10));
pLabel->setColor(ccc3(200,200,255));
pSprite->addChild(pLabel);
//信息
pLabel = CCLabelTTF::labelWithString(m_strMessage.c_str(), "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(size.width/2, size.height/2));
pLabel->setColor(ccc3(155,155,255));
pSprite->addChild(pLabel);
//添加按钮
CCMenu *pMenu = CCMenu::menuWithItems(NULL);
pMenu->setPosition(CCPointZero);
CCMenuItem *pItem;
if (m_popEnum == POPUP_YESNOCANCEL)
{
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_YES);
pItem->setPosition(ccp(size.width*3/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_NO);
pItem->setPosition(ccp(size.width*5/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("取消", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_CANCEL);
pItem->setPosition(ccp(size.width*7/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("关闭", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
}
else if (m_popEnum == POPUP_YESNO)
{
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_YES);
pItem->setPosition(ccp(size.width*3/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_NO);
pItem->setPosition(ccp(size.width*5/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("取消", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
}
else if (m_popEnum == POPUP_YES)
{
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_YES);
pItem->setPosition(ccp(size.width*3/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
}
addChild(pMenu);
return true;
}
示例7: init
bool HelloWorld::init()
{
bool bRet = false;
do
{
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
CC_BREAK_IF(! pCloseItem);
pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
CC_BREAK_IF(! pMenu);
this->addChild(pMenu, 1);
//解析tmx地图
map = CCTMXTiledMap::tiledMapWithTMXFile("0.tmx");
addChild(map);
CCArray * pChildrenArray = map->getChildren();
CCSpriteBatchNode* child = NULL;
CCObject* pObject = NULL;
//遍历Tilemap的所有图层
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = (CCSpriteBatchNode*)pObject;
if(!child)
break;
//给图层的纹理开启抗锯齿
child->getTexture()->setAntiAliasTexParameters();
}
walkAnimation = new CCAnimation*[4];
walkAnimation[kDown] = createAnimationByDirection(kDown);
walkAnimation[kRight] = createAnimationByDirection(kRight);
walkAnimation[kLeft] = createAnimationByDirection(kLeft);
walkAnimation[kUp] = createAnimationByDirection(kUp);
//用frame0作为勇士的静态图
heroSprite = CCSprite::spriteWithSpriteFrame(walkAnimation[kDown]->getFrames()->getObjectAtIndex(0));
//heroSprite->setPosition(ccp(48, 48));
heroSprite->setAnchorPoint(CCPointZero);
heroSprite->setPosition(positionForTileCoord(ccp(1, 11)));
addChild(heroSprite);
isHeroWalking = false;
CCMenuItem *down = CCMenuItemFont::itemFromString("down", this, menu_selector(HelloWorld::menuCallBackMove));
CCMenuItem *left = CCMenuItemFont::itemFromString("left", this, menu_selector(HelloWorld::menuCallBackMove) );
CCMenuItem *right = CCMenuItemFont::itemFromString("right", this, menu_selector(HelloWorld::menuCallBackMove) );
CCMenuItem *up = CCMenuItemFont::itemFromString("up", this, menu_selector(HelloWorld::menuCallBackMove) );
CCMenu* menu = CCMenu::menuWithItems(down, left, right, up, NULL);
//为了方便查找,给每个menuItem设置tag
down->setTag(kDown);
left->setTag(kLeft);
right->setTag(kRight);
up->setTag(kUp);
//菜单项按间距50水平排列
menu->alignItemsHorizontallyWithPadding(50);
addChild(menu);
schedule(schedule_selector(HelloWorld::update));
bRet = true;
} while (0);
示例8: init
// on "init" you need to initialize your instance
bool TableBar::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
//每个项目都要创建的东西
_menu = CCMenu::create(NULL);
_menu->setPosition(CCPointZero);
this->addChild(_menu, zNum+1);
pTabBar = CCSprite::create("pTabBar.png");
pTabBar->setPosition(ccp(1024.0,49.0));
this->addChild(pTabBar,zNum);
m_highlightSp = CCSprite::create("pTabBarSelectedHighlight.png");
string plistStr = TableBar::classPlistName;
plistStr += ".plist";
plistDic = CCDictionary::createWithContentsOfFile(plistStr.c_str());
for (int i = 0; i<itemVec.size(); i++)
{
const char * picNameStr = (itemVec[i]+".png").c_str();
CCSprite * aSprite = CCSprite::create(picNameStr);
if (i == TableBar::mainItemNum)
{
mainitemSprite = aSprite;
}
const char * positionName = itemVec[i].c_str();
aSprite->setPosition(ScriptParser::getPositionFromPlist(plistDic,positionName));
this->addChild(aSprite,zNum);
CCMenuItem * aItem = CCMenuItem::create(this, menu_selector(TableBar::menuselect));
aItem->setPosition(aSprite->getPosition());
aItem->setContentSize(m_highlightSp->getContentSize());
_menu ->addChild(aItem,zNum);
aItem->setTag(i);
const char * itemTitleStr = itemTitleVec[i].c_str();
CCLabelTTF* pLabel = CCLabelTTF::create(itemTitleStr,fontName_macro,fontSize_macro);
if (i == TableBar::mainItemNum)
{
pLabel->setColor(White_macro);
}
else
{
pLabel->setColor(gray_macro);
}
const char * labelNameStr = (itemVec[i]+"Label").c_str();
pLabel->setPosition(ScriptParser::getPositionFromPlist(plistDic,labelNameStr));
this->addChild(pLabel, zNum);
}
m_highlightSp->setPosition(ccp(mainitemSprite->getPosition().x,pTabBar->getPosition().y+pTabBar->getContentSize().height/2-50));
this->addChild(m_highlightSp,zNum);
m_highlightSp->setColor(ccc3(200, 200, 200));
return true;
}