本文整理汇总了C++中CCMenuItemImage::initWithNormalSprite方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemImage::initWithNormalSprite方法的具体用法?C++ CCMenuItemImage::initWithNormalSprite怎么用?C++ CCMenuItemImage::initWithNormalSprite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemImage
的用法示例。
在下文中一共展示了CCMenuItemImage::initWithNormalSprite方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool GameOverLayer::init()
{
bool bRet = false;
do
{
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint visibleOrigin = CCDirector::sharedDirector()->getVisibleOrigin();
CCSprite* gameOverBg = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("gameover.png"));
gameOverBg->setPosition(ccp(visibleOrigin.x + visibleSize.width/2, visibleOrigin.y + visibleSize.height/2));
this->addChild(gameOverBg);
passScoreItem=CCLabelBMFont::create("0", "font/font.fnt");
passScoreItem->setColor(ccc3(143, 146, 147)); //灰白色
passScoreItem->setAnchorPoint(ccp(0.5, 0.5));
passScoreItem->setPosition(ccp(visibleOrigin.x + visibleSize.width/2, visibleOrigin.y + visibleSize.height/2));
CCString* strScore = CCString::createWithFormat("%d", this->thisTimeGetscore); //格式化为字符串
passScoreItem->setString(strScore->m_sString.c_str()); //从CCString中获得char*,更新分数
this->addChild(passScoreItem);
CCLabelTTF* highestScoreItem = CCLabelTTF::create("", "Arial", 24);
highestScoreItem->setColor(ccc3(3, 3, 3)); //黑色
CCString* highestScore=CCString::createWithFormat("highestScore:%d", GameOverLayer::highestHistoryScore);
highestScoreItem->setString(highestScore->m_sString.c_str());
highestScoreItem->setPosition(ccp(visibleOrigin.x + highestScoreItem->getContentSize().width/2,
visibleOrigin.y + visibleSize.height - highestScoreItem->getContentSize().height));
this->addChild(highestScoreItem);
if (thisTimeGetscore > GameOverLayer::highestHistoryScore)
{
CCUserDefault::sharedUserDefault()->setIntegerForKey("HighestScore", thisTimeGetscore); //修改存档
CCUserDefault::sharedUserDefault()->flush();
GameOverLayer::highestHistoryScore = thisTimeGetscore; //最高分重新设定
}
CCDelayTime* delay = CCDelayTime::create(1.0f);
CCScaleTo* scaleBig = CCScaleTo::create(1.0f, 3.0f);
CCScaleTo* scaleLittle = CCScaleTo::create(0.3f, 2.0f);
CCFiniteTimeAction* sequence = CCSequence::create(delay, scaleBig, scaleLittle, NULL);
passScoreItem->runAction(sequence);
CCSprite* normalPause = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png"));
CCSprite* pressedPause = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png"));
CCMenuItemImage* restartGame = CCMenuItemImage::create();
restartGame->initWithNormalSprite(normalPause, pressedPause, NULL, this, menu_selector(GameOverLayer::restartGame));
restartGame->setPosition(ccp(visibleOrigin.x + visibleSize.width - normalPause->getContentSize().width,
visibleOrigin.y + normalPause->getContentSize().height));
CCMenu* menu = CCMenu::create(restartGame, NULL);
menu->setPosition(CCPointZero);
this->addChild(menu, 10);
bRet = true;
}while(0);
return bRet;
}
示例2: create
CCMenuItemImage* TMenuItemImage::create(const char *img, CCObject* target, SEL_MenuHandler selector)
{
CCMenuItemImage *pRet = new TMenuItemImage();
CCTexture2D* ptex = CCTextureCache::sharedTextureCache()->addImage( img );
int tw = ptex->getContentSize().width / 4;
int th = ptex->getContentSize().height;
CCNode* normal = CCSprite::createWithTexture( ptex, CCRect(0, 0, tw, th ) );
CCNode *selected = CCSprite::createWithTexture(ptex, CCRect( tw*2, 0, tw, th) );
CCNode *disabled = CCSprite::createWithTexture( ptex, CCRect( tw*3, 0, tw, th) );
pRet->initWithNormalSprite(normal, selected, disabled, target, selector);
pRet->autorelease();
return pRet;
}
示例3: init
bool GameOverLayer::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(!CCLayer::init());
//停止背景音乐,播放gameover的音效
if (CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
{
CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
}
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/game_over.mp3");
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
//加载gameover_background
CCSprite* background = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("gameover.png"));
background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(background);
//加载BackMenu
CCSprite* normalBackToGame = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png"));//正常状态下的按钮图片
CCSprite* pressedBackToGame = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png"));//按下状态下的按钮图片
CCMenuItemImage* pBackItem = CCMenuItemImage::create();//创建menu的item
pBackItem->initWithNormalSprite(normalBackToGame, pressedBackToGame, NULL, this, menu_selector(GameOverLayer::menuBackCallback));//设置
pBackItem->setPosition(ccp(winSize.width - normalBackToGame->getContentSize().width / 2 - 10, normalBackToGame->getContentSize().height / 2 + 10));//位置
CCMenu *menuBack = CCMenu::create(pBackItem, NULL);//创建menu并加入item
menuBack->setPosition(Point::ZERO);//位置
this->addChild(menuBack);//加入layer
//加载score
CCString* strScore = CCString::createWithFormat("%d", score);
CCLabelBMFont* finalScore = CCLabelBMFont::create(strScore->_string.c_str(), "res/assets/font/font.fnt");
finalScore->setColor(ccc3(143, 146, 147));
finalScore->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(finalScore);
CCDelayTime* delay = CCDelayTime::create(1.0f);
CCScaleTo* scalebig = CCScaleTo::create(1.0f, 3.0f);
CCScaleTo* scalelittle = CCScaleTo::create(0.3f, 2.0f);
CCCallFunc* showAD = CCCallFunc::create(this, callfunc_selector(GameOverLayer::showAD));
CCFiniteTimeAction* sequence = CCSequence::create(delay, scalebig, scalelittle, showAD, NULL);
finalScore->runAction(sequence);
//加载历史最高分
//CCLabelTTF* tip=CCLabelTTF::create("Congratulations! Your Score is","Monaco",20);
//tip->setColor(ccc3(143,146,147));
//tip->setPosition(ccp(finalScore->getPosition().x,finalScore->getPosition().y+finalScore->getContentSize().height+50));
//this->addChild(tip);
CCString* strHighestScore = CCString::createWithFormat("%d", highestHistoryScore);
highestScore = CCLabelBMFont::create(strHighestScore->_string.c_str(), "res/assets/font/font.fnt");
highestScore->setColor(ccc3(143, 146, 147));
highestScore->setAnchorPoint(ccp(0, 0.5));//设置锚点,即为缩放等操作的发生点。
highestScore->setPosition(ccp(140, winSize.height - 30));
this->addChild(highestScore);
//如果分数比最高分高,则更新最高分,并显示,播放动画
if (score > highestHistoryScore)
{
CCUserDefault::sharedUserDefault()->setIntegerForKey("HighestScore", score);
highestHistoryScore = score;
CCDelayTime* delayChange = CCDelayTime::create(1.3f);
CCMoveBy* moveOut = CCMoveBy::create(0.1f, ccp(0, 100));
CCCallFuncN* beginChange = CCCallFuncN::create(this, callfuncN_selector(GameOverLayer::beginChangeHighestScore));
CCMoveBy* moveIn = CCMoveBy::create(0.1f, ccp(0, -100));
CCFiniteTimeAction* sequence = CCSequence::create(delayChange, moveOut, beginChange, moveIn, NULL);
highestScore->runAction(sequence);
}
this->setKeypadEnabled(true);
bRet = true;
} while (0);
return bRet;
}
示例4: onEnter
void GameScene::onEnter()
{
CCNode::onEnter();
// 把图片添加进全局的精灵框帧缓存中
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ui/flappy_frame.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ui/flappy_packer.plist");
// 获得窗体大小
CCSize winSize =CCDirector::sharedDirector()->getWinSize();
// 添加背景图片1被设置位置
CCSprite *bg= CCSprite::create("ui/bg.png");
bg->setAnchorPoint(ccp(0,0));
bg->setPosition(ccp(0,0));
bg->setScale(0.7);
this->addChild(bg);
// 添加背景图片2被设置位置
ground1 =CCSprite::create("ui/ground.png");
ground1->setAnchorPoint(ccp(0,0));
ground1->setPosition(ccp(0,0));
ground1->setScaleY(0.7);
ground1->setZOrder(10);
this->addChild(ground1);
// 添加ground
ground2 =CCSprite::create("ui/ground.png");
ground2->setAnchorPoint(ccp(0,0));
ground2->setPosition(ccp(winSize.width,0));
ground2->setZOrder(10);
ground2->setScaleY(0.7);
this->addChild(ground2);
// 添加FlappyBirdLogo
CCSprite *flappyBird =CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("flappybird.png"));
flappyBird->setPosition(ccp(winSize.width/2,winSize.height/4*3));
flappyBird->setScale(0.6);
flappyBird->setTag(TAG_LOGO);
this->addChild(flappyBird);
// 添加GameOver
CCSprite *gameOver=CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("gameover.png"));
gameOver->setPosition(ccp(winSize.width/2,winSize.height/4*3));
gameOver->setScale(0.6);
gameOver->setTag(TAG_OVER);
gameOver->setZOrder(10);
gameOver->setVisible(false);
this->addChild(gameOver);
// 添加GetReady精灵
CCSprite *getready =CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("getready.png"));
getready->setPosition(ccp(winSize.width/2,winSize.height/4*3-50));
getready->setScale(0.6);
getready->setTag(TAG_READY);
getready->setVisible(false);
this->addChild(getready);
// 添加开始按钮
CCSprite *normalStart =CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("start.png"));
CCSprite *pressStart =CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("start1.png"));
CCMenuItemImage* startBtn=CCMenuItemImage::create();
startBtn->initWithNormalSprite(normalStart,pressStart,NULL,this,menu_selector(GameScene::gameStart));
CCMenu *menuStart =CCMenu::create(startBtn,NULL);
menuStart->setPosition(ccp(winSize.width/16,ground1->boundingBox().size.height/2-30));
menuStart->setTag(TAG_START_BTN);
menuStart->setScale(0.6);
menuStart->setZOrder(10);
this->addChild(menuStart);
// 添加退出按钮
CCSprite *normalEnd =CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("grade.png"));
CCMenuItemImage *endBtn =CCMenuItemImage::create();
endBtn->initWithNormalSprite(normalEnd,normalEnd,NULL,this,menu_selector(GameScene::gameEnd));
CCMenu *menuEnd =CCMenu::create(endBtn,NULL);
menuEnd->setPosition(ccp(winSize.width/2,ground1->boundingBox().size.height/2-30));
menuEnd->setTag(Tage_End_BTN);
menuEnd->setScale(0.6);
menuEnd->setZOrder(10);
this->addChild(menuEnd);
// 添加click图片
CCSprite *click =CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("click.png"));
click->setPosition(ccp(winSize.width/2,winSize.height/2));
click->setScale(0.6);
click->setTag(TAG_CLICK);
click->setVisible(false);
this->addChild(click);
this->birdReadyAction();
// 添加Score
CCLabelBMFont *score=CCLabelBMFont::create("0","fonts/futura-48.fnt");
score->setPosition(ccp(winSize.width/2,winSize.height/4*3+60));
score->setTag(TAG_SCORE);
score->setVisible(false);
score->setZOrder(10);
this->addChild(score);
// 添加记录
CCSprite *record =CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("base.png"));
record->setPosition(ccp(winSize.width/2,winSize.height/2+30));
record->setScaleX(0.6);
record->setScaleY(0.6);
record->setTag(TAG_RECORD);
record->setVisible(false);
record->setZOrder(10);
this->addChild(record);
hose=Hose::create();
this->addChild(hose);
// 预加载音效
preloadMusic();
// 设置可触摸
this->setTouchEnabled(true);
//.........这里部分代码省略.........