本文整理汇总了C++中CCMenuItemImage::setUserData方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemImage::setUserData方法的具体用法?C++ CCMenuItemImage::setUserData怎么用?C++ CCMenuItemImage::setUserData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemImage
的用法示例。
在下文中一共展示了CCMenuItemImage::setUserData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateGroupGameRoom
void CGroupInfoScene::CreateGroupGameRoom()
{
// 最后一个为新加的,draw it
vector<CGameRoomInfo> &rooms = CGameManager::Instance().GetGameRoomInfo();
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
float w = visibleSize.width/ 2;
float h = visibleSize.height - 120;
CCMenuItemImage *pAddItem = CCMenuItemImage::create(
PATCH_RES_DIR("group_room.png"),
PATCH_RES_DIR("group_room.png"),
this,
menu_selector(CGroupInfoScene::menuEnterGroupGameRoomCallback) );
h -= (rooms.size()-1) * (pAddItem->getContentSize().height + 5);
pAddItem->setAnchorPoint( ccp(0, 0) );
pAddItem->setPosition( ccp(w, h) );
pAddItem->setUserData( &rooms[rooms.size()-1] );
CCMenu *pMenu = CCMenu::create( pAddItem, NULL );
pMenu->setPosition( CCPointZero );
addChild( pMenu, 1 );
}
示例2:
CCMenuItemImage* Objects2dFactory::imageButton(CCNode* scene, CCMenu* menu, string normalImagePath, string selectedImagePath, string disabledImagePath,
float positionX, float positionY, float width, float height, SEL_MenuHandler selector, void* selectorArg, AlignX alignX, AlignY alignY, int zOrder)
{
// Check arguments validity
if(scene == NULL || menu == NULL || !selector)
return NULL;
// Create a button menu item
CCMenuItemImage *button = CCMenuItemImage::create(
normalImagePath.c_str(),
selectedImagePath.c_str(),
disabledImagePath.c_str(),
scene,
selector);
if(!button)
return NULL;
if (selectorArg != NULL)
{
button->setUserData(selectorArg);
}
// Place the menu item in the given position
button->setPosition(ccp(positionX, positionY));
// Set anchor
button->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
// Set menu item width
float buttonWidth = button->boundingBox().size.width;
if (width > 0) // if width is defined, it is setted
{
button->setScaleX(width / buttonWidth);
}
// Set menu item height
float buttonHeight = button->boundingBox().size.height;
if (height > 0) // if height is defined, it is setted
{
button->setScaleY(height / buttonHeight);
}
// Add button to the menu
menu->addChild(button, zOrder);
return button;
}
示例3: initItem
bool ChuanqiduanzaoItem::initItem(BaseActor* info)
{
bool bret = false;
//初始化背景
if (CCSprite::initWithFile("shangdian_chuanqi_bg.png"))
{
bret = true;
}
if (bret)
{
m_Profession_id = info->getCurrentProperty().profession;
//顶部文字显示
CCLabelTTF* pTopTip = CCLabelTTF::create(LFStrings::getValue("ShenBingDuanZao_ShuoMingTiShi").c_str(), fontStr_kaiti, 18);
pTopTip->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height-70));
pTopTip->setColor(fonColor_FaGuang);
this->addChild(pTopTip);
//头像
CCSprite* pIcon = CCSprite::create(this->getIconFileNameByType(info->getActorType()).c_str());
this->addChild(pIcon);
pIcon->setPosition(ccp(this->getContentSize().width/2, 400));
//美术字(英雄类型)
CCSprite* pHeroType = CCSprite::create(this->getHeroTypeFileNameByType(info->getActorType()).c_str());
this->addChild(pHeroType);
pHeroType->setPosition(ccp(this->getContentSize().width/2,
pIcon->getPositionY()-pIcon->getContentSize().height/2-pHeroType->getContentSize().height+2));
//套装名字
string zhuangBeiStr = ChuanqiPool::getPool()->getChuanQiSuitName(info->getActorType());
CCLabelTTF* pName = CCLabelTTF::create(zhuangBeiStr.c_str(), fontStr_kaiti, 20);
pName->setPosition(ccp(this->getContentSize().width/2, 280));
this->addChild(pName);
CCMenu* pMenu = CCMenu::create();
this->addChild(pMenu);
pMenu->setPosition(CCPointZero);
//锻造一次
CCMenuItemImage *yici = CCMenuItemImage::create(
"shangdian_shenbin_anniu_duanzaoyici.png",
"shangdian_shenbin_anniu_duanzaoyici_select.png",
this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_DuanZao));
pMenu->addChild(yici, 0, Tag_MenuItem_Yici);
yici->setPosition(ccp(this->getContentSize().width/2-yici->getContentSize().width/2, 185));
yici->setUserData((void*)info->getActorType());
//锻造十次
CCMenuItemImage *shici = CCMenuItemImage::create(
"shangdian_shenbin_anniu_duanzaoshici.png",
"shangdian_shenbin_anniu_duanzaoshici_select.png",
this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_DuanZao));
pMenu->addChild(shici, 0, Tag_MenuItem_Shici);
shici->setPosition(ccp(this->getContentSize().width/2+yici->getContentSize().width/2, yici->getPositionY()));
shici->setUserData((void*)info->getActorType());
char buf[20];
//锻造一次需要金币
BaseSprite *goldIcon1 = BaseSprite::create("jinbi_tubiao.png");
this->addChild(goldIcon1);
goldIcon1->setScale(0.5f);
goldIcon1->setPosition(ccp(yici->getPositionX()-goldIcon1->getContentSize().width/2, yici->getPositionY()+yici->getContentSize().height/2+goldIcon1->getContentSize().height/2));
sprintf(buf, "%d", 400);
CCLabelTTF *yiciLabel = CCLabelTTF::create(buf, fontStr_BookAntiqua, 20);
this->addChild(yiciLabel);
yiciLabel->setPosition(ccp(goldIcon1->getPositionX()+goldIcon1->getContentSize().width/2*goldIcon1->getScaleX()+yiciLabel->getContentSize().width/2
, goldIcon1->getPositionY()));
//锻造十次需要金币
BaseSprite *goldIcon10 = BaseSprite::create("jinbi_tubiao.png");
this->addChild(goldIcon10);
goldIcon10->setScale(0.5f);
goldIcon10->setPosition(ccp(shici->getPositionX()-goldIcon10->getContentSize().width/2, shici->getPositionY()+shici->getContentSize().height/2+goldIcon10->getContentSize().height/2));
sprintf(buf, "%d", 400*10);
CCLabelTTF *yiciLabel0 = CCLabelTTF::create(buf, fontStr_BookAntiqua, 20);
this->addChild(yiciLabel0);
yiciLabel0->setPosition(ccp(goldIcon10->getPositionX()+goldIcon10->getContentSize().width/2*goldIcon10->getScaleX()+yiciLabel0->getContentSize().width/2
, goldIcon10->getPositionY()));
CCMenuItemImage* pXiaoguo = CCMenuItemImage::create(
"shandian_anniu_taozhuangxiaoguo.png",
"shandian_anniu_taozhuangxiaoguo_select.png",
this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_Xiaoguo)
);
pMenu->addChild(pXiaoguo);
pXiaoguo->setPosition(ccp(this->getContentSize().width/2, pXiaoguo->getContentSize().height/2));
}
return bret;
}