本文整理汇总了C++中CCMenuItemImage::setTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemImage::setTarget方法的具体用法?C++ CCMenuItemImage::setTarget怎么用?C++ CCMenuItemImage::setTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemImage
的用法示例。
在下文中一共展示了CCMenuItemImage::setTarget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startGame
void TetrisGameLayer::startGame(){
G_current_HandleType = new LongBlock_Type();
G_current_HandleType->init();
CCSize size = CCDirector::sharedDirector()->getWinSize();
//控制按钮//
CCMenuItemImage * left = CCMenuItemImage::create("left.png", "left.png");
left->setTarget(this, menu_selector(TetrisGameLayer::leftButtonPressed));
left->setScale(0.5);
CCMenuItemImage * right = CCMenuItemImage::create("right.png", "right.png");
right->setTarget(this, menu_selector(TetrisGameLayer::rightButtonPressed));
left->setAnchorPoint(ccp(0, 0));
right->setAnchorPoint(ccp(0, 0));
right->setScale(0.5);
right->setPosition(ccp(size.width/2+size.width/4, 0));
CCMenuItemImage * down = CCMenuItemImage::create("down.png", "down.png");
down->setTarget(this, menu_selector(TetrisGameLayer::downButtonPressed));
down->setAnchorPoint(ccp(0,0));
down->setScale(0.5);
down->setPosition(ccp(size.width/2 -100,0));
down->setOpacity(0.7*255);
CCMenu * menu = CCMenu::create(left,down,right, NULL);
menu->setAnchorPoint(ccp(0, 0));
menu->setPosition(ccp(0, 0));
this->addChild(menu);
}
示例2: buildScene
void ScoreAPIScene::buildScene()
{
// Call super build scene.
BaseScene::buildScene();
BaseScene::addTipBoard("Do you know that store user score on Facebook? Compare friends score and build a leaderboard in just 1 function call");
CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create(PNG_FILE(kRESOURCE_SCORE));
this->addChild(batchNode);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(PLIST_FILE(kRESOURCE_SCORE));
buildHeader(-1, "Score APIs", "Generate interesting stories by updating scores");
CCMenuItemImage* menuItem = NULL;
menuItem = this->buildAndPlaceTile("btn_reset_score_nrl", "btn_reset_score_prd", 1, 0);
menuItem->setTarget(this, menu_selector(ScoreAPIScene::resetUserScore));
menuItem = this->buildAndPlaceTile("btn_submit_score_nrl", "btn_submit_score_prd", 1, 1);
menuItem->setTarget(this, menu_selector(ScoreAPIScene::submitUserScore));
//menuItem = this->buildAndPlaceTile("btn_reset_tournament_nrl", "btn_reset_tournament_prd", 1, 1);
//menuItem->setTarget(this, menu_selector(ScoreAPIScene::resetTournamentScore));
menuItem = this->buildAndPlaceTile("btn_achievement_nrl", "btn_achievement_prd", 0, 2);
menuItem->setTarget(this, menu_selector(ScoreAPIScene::publishAnAchievement));
}
示例3: buildScene
void FeedAPIScene::buildScene()
{
// Call super build scene.
BaseScene::buildScene();
BaseScene::addTipBoard("Do you know that can actually publish on user wall without notifying him? Just try not so often to avoid getting your app blocked by user.");
CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create(PNG_FILE(kRESOURCE_FEED_API));
this->addChild(batchNode);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(PLIST_FILE(kRESOURCE_FEED_API));
buildHeader(-1, "Feed APIs", "Fetch the details of user from Facebook");
CCMenuItemImage* menuItem = NULL;
menuItem = this->buildAndPlaceTile("btn_post_message_nrl", "btn_post_message_prd", 0, 0);
menuItem->setTarget(this, menu_selector(FeedAPIScene::postMessageOnUserWall));
menuItem = this->buildAndPlaceTile("btn_auto_post_message_nrl", "btn_auto_post_message_prd", 1, 1);
menuItem->setTarget(this, menu_selector(FeedAPIScene::autoPostMessageOnUserWall));
menuItem = this->buildAndPlaceTile("btn_post_photo_nrl", "btn_post_photo_prd", 0, 2);
menuItem->setTarget(this, menu_selector(FeedAPIScene::postPhotoInUserAlbum));
}
示例4: onLoadScene
//-------------------------------------------------------------------------
// 其他逻辑初始化
void CShopTestScene::onLoadScene()
{
setAutoRemoveUnusedTexture( true );
// 根窗口,用来挂载显示物件
{
m_pRootWindow = FKCW_UIWidget_WidgetWindow::create();
m_pRootWindow->setMultiTouchEnabled(true);
this->addChild(m_pRootWindow);
}
// 返回按钮
{
CCMenu *pMenu = CCMenu::create();
pMenu->setPosition(CCPointZero);
addChild(pMenu);
CCMenuItemImage* pBtn = CCMenuItemImage::create();
CCSpriteFrame* pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("back_button_normal_e.png");
pBtn->setNormalSpriteFrame(pFrame);
pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("back_button_touch_e.png");
pBtn->setSelectedSpriteFrame(pFrame);
pBtn->setTarget(this, menu_selector(CShopTestScene::onClick));
pBtn->setPosition(SCREEN_CENTER_POS + ccp(0,400));
pMenu->addChild(pBtn);
}
}
示例5: receivePersonalData
void LayerLogin::receivePersonalData(){
Message* revMsg1 = (Message *)CData::getCData()->m_dictionary->objectForKey(103);
CData::getCData()->m_dictionary->removeObjectForKey(103);
if(revMsg1){
this->unschedule(schedule_selector(LayerLogin::receivePersonalData));
// editBoxUsername->removeFromParent();
// editBoxPassword->removeFromParent();
denglu1=revMsg1->data;
CData::getCData()->setSendVal(denglu1);
printf("------%s\n",denglu1);
pSpriteDialogLogin->removeFromParent();
load->removeFromParent();
// CCSprite *pSpriteselector = CCSprite::createWithSpriteFrameName("button_bg.png");// CCSprite::create("button_bg.png");
// CCMenuItemSprite *pMenuItemSelector = CCMenuItemSprite::create(pSpriteselector, pSpriteselector, this,SEL_MenuHandler(&LayerLogin::menuItemCallbackStart));
// pMenuItemSelector->setPosition(0, 130);
// CCMenuItemImage *pMenuItemStart = CCMenuItemImage::create("start_up.png", "start_down.png", this,SEL_MenuHandler(&LayerLogin::menuItemCallbackStart));
CCMenuItemImage *pMenuItemStart = CCMenuItemImage::create();
pMenuItemStart->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("login_start_1.png"));
pMenuItemStart->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("login_start_2.png"));
pMenuItemStart->setTarget(this, SEL_MenuHandler(&LayerLogin::menuItemCallbackStart));
CCMenu *pMenu = CCMenu::create(pMenuItemStart,NULL);
this->addChild(pMenu,2);
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
pMenu->setPosition(winSize.width/2, 180);
}
}
示例6: initClickMenu
void BalloonItemClick::initClickMenu(CCSprite* pSpriteIcon)
{
// 加载按钮图形
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("texture/items/items.plist");
// 创建按钮
CCMenuItemImage* pMenuItemImage = CCMenuItemImage::create();
// 设置按钮的图片
// pMenuItemImage->setNormalImage(CCSprite::create("texture/items/item_btn_normal.png"));
pMenuItemImage->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("item_btn_normal.png"));
// pMenuItemImage->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("item_btn_normal.png"));
// 顺便这里更新下控件的大小
setContentSize(pMenuItemImage->getContentSize());
// 设置按下后的回调函数
pMenuItemImage->setTarget(this, menu_selector(BalloonItemClick::onPressMenuClick));
// 设置按钮
m_pMenuClick = CCMenu::create();
m_pMenuClick->addChild(pMenuItemImage);
CC_SAFE_RETAIN(m_pMenuClick);
// 设置按钮居中对齐
m_pMenuClick->setPosition(ccpMult(ccpFromSize(getContentSize()), 0.5f));
// 设置按下后的图片放大效果
ControlUtil::sharedControlUtil()->SetMenuItemSelectedImageWithNormalImage(m_pMenuClick, 1.2f);
// 添加到界面上
addChild(m_pMenuClick);
m_pSpriteIcon = pSpriteIcon;
m_pSpriteIcon->setPosition(ccpMult(ccpFromSize(getContentSize()), 0.5f));
CC_SAFE_RETAIN(m_pSpriteIcon);
addChild(m_pSpriteIcon);
}
示例7: createPauseLayer
void GameLayer::createPauseLayer() {
Context *context = Context::sharedContext();
CCSize s = CCDirector::sharedDirector()->getWinSize();
/* 半透明层 */
CCLayerColor* pauseLayer = CCLayerColor::create();
pauseLayer->setContentSize(CCSizeMake(s.width, s.height));
pauseLayer->setColor(ccc3(0, 0, 0));
pauseLayer->setOpacity(150);
CCMenu *menu = CCMenu::create();
//回到游戏
CCMenuItemImage *resumebg = CCMenuItemImage::create(("btn_big.png"),
("btn_big.png"));
resumebg->setTarget(this, menu_selector(GameLayer::onResumeItem));
CCMenuItemFont *resumetxt = CCMenuItemFont::create(LOCAL_RESOURCES->valueByKey("i18n_resume")->getCString());
resumebg->setAnchorPoint(ccp(0.5, 0.5));
resumebg->setPosition(ccpp(0, 0));
resumetxt->setPosition(
ccp(resumebg->getContentSize().width / 2,
resumebg->getContentSize().height / 2));
resumetxt->setAnchorPoint(ccp(0.5, 0.5));
resumetxt->setColor(context->getFontColor());
resumebg->addChild(resumetxt);
menu->addChild(resumebg);
//回到菜单
CCMenuItemImage *backbg = CCMenuItemImage::create(("btn_big.png"),
("btn_big.png"));
backbg->setTarget(this, menu_selector(GameLayer::onBackItem));
CCMenuItemFont *backtxt = CCMenuItemFont::create(LOCAL_RESOURCES->valueByKey("i18n_back")->getCString());
backbg->setAnchorPoint(ccp(0.5, 0.5));
backbg->setPosition(ccpp(0, -0.12));
backtxt->setPosition(
ccp(backbg->getContentSize().width / 2,
backbg->getContentSize().height / 2));
backtxt->setAnchorPoint(ccp(0.5, 0.5));
backtxt->setColor(context->getFontColor());
backbg->addChild(backtxt);
menu->addChild(backbg);
pauseLayer->addChild(menu);
CCDirector::sharedDirector()->getRunningScene()->addChild(pauseLayer, 0,
TAG_LAYER_PAUSE);
}
示例8: addMenu
void StartLayer::addMenu()
{
CCMenuItemImage *singleItem = CCMenuItemImage::create("btn_start_single_1-hd.png", "btn_start_single_2-hd.png");
singleItem->setTarget(this, menu_selector(StartLayer::clickSingleMenu));
singleItem->setPosition(-210,-122);
CCMenuItemImage *mutipleItem = CCMenuItemImage::create("btn_start_multi_1-hd.png", "btn_start_multi_2-hd.png");
mutipleItem->setTarget(this, menu_selector(StartLayer::clickMultipleMenu));
mutipleItem->setPosition(ccp(223, -120));
CCMenuItemImage *otherItm = CCMenuItemImage::create("btn_start_updatead_1-hd.png","btn_start_updatead_2-hd.png", this, menu_selector(StartLayer::clickOtherMenu));
otherItm->setPosition(80, -228);
CCMenu *menu = CCMenu::create(singleItem,mutipleItem,otherItm,NULL);
this->addChild(menu);
}
示例9: addBackButton
void HelloWorld::addBackButton(CCScene *s){
// CCScene *currentScene = CCDirector::sharedDirector()->getRunningScene();
CCSize size = CCDirector::sharedDirector()->getWinSize();
//布置菜单的layer
CCMenu *menu = CCMenu::create();
menu->setPosition(CCPointZero);//菜单锚点被设为0.5 0.5了,改回来
s->addChild(menu);
CCMenuItemImage *item = CCMenuItemImage::create("home.png", "home.png");
item->setPosition(ccp(size.width-50, size.height-50));
menu->addChild(item);
item->setTarget(this, menu_selector(HelloWorld::returnCallback));
}
示例10: init
bool StartScene::init()
{
if (!CCLayer::init()) {
return false;
}
CCSize winsize = CCDirector::sharedDirector()->getWinSize();
CCSprite* bgsprite = CCSprite::create("bg54.jpg");
bgsprite->setScale(0.6);
bgsprite->setPosition(ccp(winsize.width/2, winsize.height/2));
this->addChild(bgsprite);
CCSprite* bgtitle = CCSprite::create("bgtitle.png");
bgtitle->setScale(0.35);
bgtitle->setPosition(ccp(winsize.width/2, winsize.height/2+100));
this->addChild(bgtitle);
CCSprite* bg = CCSprite::create("gamebg.png");
bg->setScale(0.6);
bg->setPosition(ccp(winsize.width/2, winsize.height/2-25));
this->addChild(bg);
//选择按钮
CCMenuItemImage* startItem = CCMenuItemImage::create("start.png", "start.png",this,menu_selector(StartScene::startBtn));
startItem->setScale(0.6);
startItem->setPosition(ccp(winsize.width/2, winsize.height/2-25));
CCMenuItemImage* helpItem = CCMenuItemImage::create("help.png", "help.png");
helpItem->setTarget(this, menu_selector(StartScene::helpBtn));
helpItem->setScale(0.6);
helpItem->setPosition(ccp(winsize.width/2, winsize.height/2-75));
//音效按钮
CCMenuItemImage* start = CCMenuItemImage::create("music2.png", "music2.png");
CCMenuItemImage* start1 = CCMenuItemImage::create("music1.png", "music1.png");
CCMenuItemToggle* tog1 = CCMenuItemToggle::createWithTarget(this, menu_selector(StartScene::musicBtn),start,start1,NULL);
tog1->setPosition(ccp(winsize.width/2+100, winsize.height/2-25));
CCMenuItemImage* yinxiao = CCMenuItemImage::create("music3.png", "music3.png");
CCMenuItemImage* yinxiao1 = CCMenuItemImage::create("music4.png", "music4.png");
CCMenuItemToggle* tog2 = CCMenuItemToggle::createWithTarget(this, menu_selector(StartScene::yinxiaoBtn),yinxiao,yinxiao1,NULL);
tog2->setPosition(ccp(winsize.width/2+100, winsize.height/2-55));
CCMenu* menu = CCMenu::create(startItem,helpItem,tog1,tog2, NULL);
menu->setPosition(CCPointZero);
this->addChild(menu,1);
return true;
}
示例11:
CCLayer * GameLayer::createPauseButtonLayer() {
CCMenu *layer = CCMenu::create();
//暂停
CCMenuItemImage *pausebg = CCMenuItemImage::create(("btn_small.png"),
("btn_small.png"));
CCSprite *pausetxt = CCSprite::create("btn_pause.png");
pausebg->setTarget(this, menu_selector(GameLayer::onPauseItem));
pausebg->setAnchorPoint(ccp(0, 0.5));
pausebg->setPosition(ccpp(-0.49, 0.42));
pausetxt->setPosition(
ccp(pausebg->getContentSize().width / 2,
pausebg->getContentSize().height / 2));
pausetxt->setAnchorPoint(ccp(0.5, 0.5));
pausebg->addChild(pausetxt);
layer->addChild(pausebg);
return layer;
}
示例12: init
bool ActionSequence::init()
{
if(CCLayer::init())
{
CCSprite *bg = CCSprite::create("bg.png");
bg->setPosition(ccp(240, 160));
this->addChild(bg);
CCMenuItemImage *itemImage = CCMenuItemImage::create("b1.png", "b2.png");
itemImage->setTarget(this, menu_selector(ActionSequence::back));
CCMenu *backMenu = CCMenu::create(itemImage,NULL);
backMenu->setPosition(ccp(50,280));
this->addChild(backMenu);
CCMenuItemFont *item1 = CCMenuItemFont::create("CCSequence");
CCMenuItemFont *item2 = CCMenuItemFont::create("CCSpawn");
item1->setTarget(this, menu_selector(ActionSequence::showSequence));
item2->setTarget(this, menu_selector(ActionSequence::showSpawn));
CCMenu *menu = CCMenu::create(item1,item2,NULL);
menu->setColor(ccc3(0, 255, 0));
menu->alignItemsInColumns(1,1);
menu->setPosition(ccp(240,80));
this->addChild(menu);
mySprite = CCSprite::create("bird.png");
mySprite->setPosition(ccp(60, 180));
this->addChild(mySprite);
return true;
}
return false;
}
示例13: onEnter
void GameOver::onEnter()
{
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
const char* FILE_NAME = "/mnt/sdcard/ninjadash/ninjadata";
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
const char* FILE_NAME = "../assets/data";
#endif
FILE* p = fopen(FILE_NAME,"r");
if(!p)
{
FILE* w = fopen(FILE_NAME,"w");
fwrite("0",1,1,w);
fclose(w);
}
p = fopen(FILE_NAME,"r+");
char data[8] = {0};
fread(data,1,8,p);
CCString* sMax = CCString::create(data);
int nMax = sMax->intValue();
if(m_nThisScore > nMax)
{
CCString* sWrite = CCString::createWithFormat("%d",m_nThisScore);
fseek(p,0,SEEK_SET);
int l = sWrite->length();
fwrite(sWrite->getCString(),l,1,p);
}
fclose(p);
// End Haha
const float fontSize = 40.0f;
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
if( !m_bFromMenu )
{
CCSprite* background = CCSprite::create( "bg_gameover.png" );
background->setScaleX(CCEGLView::sharedOpenGLView()->getFrameSize().width / background->getContentSize().width);
background->setScaleY(CCEGLView::sharedOpenGLView()->getFrameSize().height / background->getContentSize().height);
background->setPosition( ccp( CCEGLView::sharedOpenGLView()->getFrameSize().width / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height / 2 ) );
this->addChild( background, -1 );
// Create 2 Menu Items
CCMenuItemImage* quitItem = CCMenuItemImage::create( "quit_up.png", "quit_down.png" );
quitItem->setTag( MT_Menu );
quitItem->setTarget( this, menu_selector( GameOver::menuCallback ) );
quitItem->setPosition( ccp( visibleSize.width * (1.0 - 0.3) / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height * 0.375 ) );
quitItem->setScale( 1.5f );
CCMenuItemImage* retryItem = CCMenuItemImage::create( "tryagain_up.png", "tryagain_down.png" );
retryItem->setTag( MT_Retry );
retryItem->setTarget( this, menu_selector( GameOver::menuCallback ) );
retryItem->setPosition( ccp( visibleSize.width * (1.0 + 0.3) / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height * 0.375 ) );
retryItem->setScale( 1.5f );
// Add to Menu
CCMenu* pMenu = CCMenu::create( quitItem, retryItem, NULL );
pMenu->setPosition( CCPointZero );
this->addChild( pMenu );
// Font
CCString* s1 = CCString::createWithFormat("%d",m_nThisScore);
CCLabelTTF* info1 = CCLabelTTF::create(s1->getCString(),"Stencil Std",fontSize);
info1->setPosition(CCPoint(CCEGLView::sharedOpenGLView()->getFrameSize().width / 2,CCEGLView::sharedOpenGLView()->getFrameSize().height * 1.35 / 2 ));
addChild(info1);
CCLabelTTF* info2 = CCLabelTTF::create(sMax->getCString(),"Stencil Std",fontSize);
info2->setPosition(CCPoint(CCEGLView::sharedOpenGLView()->getFrameSize().width / 2,CCEGLView::sharedOpenGLView()->getFrameSize().height * 1.1 / 2 ));
addChild(info2);
}
else
{
CCSprite* background = CCSprite::create( "bg_setting.png" );
background->setScaleX(CCEGLView::sharedOpenGLView()->getFrameSize().width / background->getContentSize().width);
background->setScaleY(CCEGLView::sharedOpenGLView()->getFrameSize().height / background->getContentSize().height);
background->setPosition( ccp( CCEGLView::sharedOpenGLView()->getFrameSize().width / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height / 2 ) );
this->addChild( background, -1 );
CCSprite* bscore = CCSprite::create( "bestscore.png" );
bscore->setScale(1.5);
bscore->setPosition( ccp( CCEGLView::sharedOpenGLView()->getFrameSize().width / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height * 0.8 ) );
this->addChild( bscore, -1 );
// Create 2 Menu Items
CCMenuItemImage* backItem = CCMenuItemImage::create( "back_up.png", "back_down.png" );
backItem->setTag( MT_Back );
backItem->setTarget( this, menu_selector( GameOver::menuCallback ) );
backItem->setPosition( ccp( visibleSize.width / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height * 0.375 ) );
backItem->setScale( 1.5f );
// Add to Menu
CCMenu* pMenu = CCMenu::create( backItem, NULL );
pMenu->setPosition( CCPointZero );
this->addChild( pMenu );
CCLabelTTF* info2 = CCLabelTTF::create(sMax->getCString(),"Stencil Std",fontSize);
//.........这里部分代码省略.........
示例14: tableCellAtIndex
CCTableViewCell* RequestList::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
int index = idx;
EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(index);
EziFacebookFriend* sender = fbRequest->getSender();
const char* senderName = sender->getName();
// Create the fancy test.
EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType();
std::string messageToDisplay = "";
switch (requestType)
{
case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE:
messageToDisplay.append(senderName).append(" has sent invitation to you.");
break;
case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT:
messageToDisplay.append(senderName).append(" has sent gift to you.");
break;
case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE:
messageToDisplay.append(senderName).append(" has challenged to you.");
break;
default:
messageToDisplay.append("Unknown message");
break;
}
// Means users have already used this request.
bool requestConsumed = fbRequest->isConsumed();
CCSprite* profilePic = NULL;
ccColor4B bgColor = ccc4(20, 0, 40, 255);
if (requestConsumed == false)
{
bgColor = ccc4(50, 50, 20, 255);
}
// Build the table cell.
CCTableViewCell *cell = table->dequeueCell();
if (cell == NULL)
{
cell = new CCTableViewCell();
cell->autorelease();
// Create the back layer of the cell.
CCLayerColor* colorLayer = CCLayerColor::create(bgColor, SCREEN_WIDTH, CELL_HEIGHT);
colorLayer->setTag(BACKGROUND_TAG);
cell->addChild(colorLayer);
// Get the sender profile picture path. Create it if path is available.
if (sender != NULL && strcmp(sender->getPhotoPath(), "") != 0)
{
const char* picPath = sender->getPhotoPath();
profilePic = CCSprite::create(picPath);
}
else
{
profilePic = CCSprite::create(FB_DEFAULT_PHOTO);
}
// Add the profile pic to the cell row.
profilePic->setAnchorPoint(ccp(0, 0.5));
profilePic->setPosition(ccp(20, CELL_HEIGHT/2));
cell->addChild(profilePic);
profilePic->setTag(FRIEND_PHOTO_TAG);
// Set the message.
CCLabelTTF *messageLabel = CCLabelTTF::create(messageToDisplay.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE);
messageLabel->setAnchorPoint(ccp(0, 0.5));
messageLabel->setPosition(ccp(20 + 20 + profilePic->getContentSize().width, CELL_HEIGHT/2));
messageLabel->setTag(REQUEST_MESSAGE_LABEL_TAG);
messageLabel->setDimensions(CCSizeMake(SCREEN_WIDTH - (profilePic->getContentSize().width * 2) - 60, CELL_HEIGHT-5));
messageLabel->setHorizontalAlignment(kCCTextAlignmentLeft);
cell->addChild(messageLabel);
CCMenuItemImage* constumeItemButton = NULL;
constumeItemButton = CCMenuItemImage::create("use.png", "use_pressed.png");
constumeItemButton->setTag(idx);
constumeItemButton->setTarget(this, menu_selector(RequestList::useItem));
constumeItemButton->setScale(SCALE_FACTOR * 0.8);
constumeItemButton->setTag(FRIEND_CONSUME_BUTTON_TAG);
CCMenu* consumeMenu = CCMenu::create(constumeItemButton, NULL);
consumeMenu->setTag(FRIEND_CONSUME_MENU_TAG);
consumeMenu->setPosition(ccp(SCREEN_WIDTH - (constumeItemButton->getContentSize().width*SCALE_FACTOR*0.4),
(CELL_HEIGHT - (constumeItemButton->getContentSize().height)*SCALE_FACTOR*0.4)));
cell->addChild(consumeMenu);
//.........这里部分代码省略.........
示例15: buildHeader
void BaseScene::buildHeader(int highlightIndex, const char* title, const char* description)
{
_currentMenuIndex = highlightIndex;
CCMenuItemImage* homeButton = CCMenuItemImage::create();
homeButton->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home_nrl"));
homeButton->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home_prd"));
homeButton->setDisabledSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_home_prd"));
homeButton->setTarget(this, menu_selector(BaseScene::loadHomeScene));
homeButton->setAnchorPoint(ccp(1.0f, 1.0f));
CCMenuItemImage* fbActionButton = CCMenuItemImage::create();
fbActionButton->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_fb_action_nrl"));
fbActionButton->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_fb_action_prd"));
fbActionButton->setDisabledSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_fb_action_dis"));
fbActionButton->setTarget(this, menu_selector(BaseScene::loadFBActionScene));
fbActionButton->setAnchorPoint(ccp(1.0f, 1.0f));
if (EziSocialObject::sharedObject()->isFacebookSessionActive() == false)
{
fbActionButton->setEnabled(false);
}
CCMenuItemImage* helpButton = CCMenuItemImage::create();
helpButton->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_help_nrl"));
helpButton->setSelectedSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_help_prd"));
helpButton->setDisabledSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_help_prd"));
helpButton->setTarget(this, menu_selector(BaseScene::loadHelpScene));
helpButton->setAnchorPoint(ccp(1.0f, 1.0f));
switch (highlightIndex)
{
case 0:
homeButton->setEnabled(false);
break;
case 1:
fbActionButton->setEnabled(false);
break;
case 2:
helpButton->setEnabled(false);
break;
default:
break;
}
CCMenu* homeMenu = CCMenu::create(homeButton, fbActionButton, helpButton, NULL);
homeMenu->alignItemsHorizontally();
this->addChild(homeMenu);
PlaceNode(homeMenu, 0.88, 0.98);
// Add a line.
CCLayerColor* lineLayer = CCLayerColor::create(ccc4(204, 204, 204, 204),
CCDirector::sharedDirector()->getVisibleSize().width,
1.0 * AppDelegate::SCREEN_SCALE_FACTOR);
this->addChild(lineLayer);
PlaceNode(lineLayer, 0.0, 0.8);
lineLayer->setPositionY(homeMenu->getPositionY() - homeButton->getContentSize().height - (7 * AppDelegate::SCREEN_SCALE_FACTOR));
// Add Title
CCLabelTTF* titleLabel = CCLabelTTF::create(title, "Arial", 50.0 * AppDelegate::SCREEN_SCALE_FACTOR);
this->addChild(titleLabel);
titleLabel->setAnchorPoint(ccp(0.0f, 0.0f));
//PlaceNode(titleLabel, 0.02, 0.98);
CCLabelTTF* descriptionLabel = CCLabelTTF::create(description,
"Arial", SCALED_VALUE(22.0f));
this->addChild(descriptionLabel);
descriptionLabel->setAnchorPoint(ccp(0.0f, 0.0f));
PlaceNode(descriptionLabel, 0.02, 0.98);
descriptionLabel->setPositionY(homeMenu->getPositionY() - homeButton->getContentSize().height);
descriptionLabel->setColor(ccc3(204, 204, 204));
titleLabel->cocos2d::CCNode::setPosition(descriptionLabel->getPositionX(),
descriptionLabel->getPositionY() + descriptionLabel->getContentSize().height - 2.0f);
}