void GameOverLayer::createPlayAgainButton() { // Create the startButton CCSprite *playAgainButtonSpriteUp = CCSprite::createWithSpriteFrameName("playagain_button.png"); CCSprite *playAgainButtonSpriteDown = CCSprite::createWithSpriteFrameName("playagain_button.png"); // Scale the down to 90% so that it looks like the button was pressed playAgainButtonSpriteDown->setScale(0.9f); CCMenuItemSprite *playAgainButton = CCMenuItemSprite::create(playAgainButtonSpriteUp, playAgainButtonSpriteDown, this, menu_selector(GameOverLayer::playAgainButtonTouched)); playAgainButton->setPositionX(-playAgainButton->getContentSize().width/1.2); playAgainButton->runAction(CCRepeatForever::create(CCSequence::createWithTwoActions(CCScaleTo::create(1.0f, 1.2f), CCScaleTo::create(1.0f, 1.0f)))); // Create the mainButton CCSprite *mainButtonSpriteUp = CCSprite::createWithSpriteFrameName("main_button.png"); CCSprite *mainButtonSpriteDown = CCSprite::createWithSpriteFrameName("main_button.png"); // Scale the down to 90% so that it looks like the button was pressed mainButtonSpriteDown->setScale(0.9f); CCMenuItemSprite *mainButton = CCMenuItemSprite::create(mainButtonSpriteUp, mainButtonSpriteDown, this, menu_selector(GameOverLayer::mainButtonTouched)); mainButton->setPositionX(mainButton->getContentSize().width/1.2); // Create the start game menu CCMenu *gameMenu = CCMenu::create(playAgainButton, mainButton, NULL); // Set the initial position off screen gameMenu->setPosition(ccp(SCREEN_WIDTH/2, -SCREEN_HEIGHT)); // Set the tag of the start menu so that we can refer to it later using getChildByTag(...) gameMenu->setTag(kGameOverLayer_PlayAgainMenu); // Create and run an animation that will slide the start game menu in from below the screen to its intended location CCActionInterval *moveAction = CCMoveTo::create(0.3f, ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.15)); CCFiniteTimeAction *easeIn = CCEaseIn::create(moveAction, 0.2f); gameMenu->runAction(easeIn); // Add the start menu to the layer this->addChild(gameMenu); }
void GameScene::showRetryButtons() { CCMenuItemImage* retryButton = CCMenuItemImage::create( "ButtonRetry.png","ButtonRetry.png", this, menu_selector(GameScene::tapRetryButton)); CCMenuItemImage* wallButton = CCMenuItemImage::create( "ButtonWall.png", "ButtonWall.png" , this, menu_selector(GameScene::tapWallButton)); CCMenuItemImage* titleButton = CCMenuItemImage::create( "ButtonTitle.png","ButtonTitle.png", this, menu_selector(GameScene::tapTitleButton)); CCMenu* menu = CCMenu::create(retryButton, wallButton, titleButton, NULL); menu->alignItemsHorizontallyWithPadding( 30.0f); menu->setOpacity(0); //menu->setPosition(ccp(m_winSize.width / 2,m_winSize.height * 1.2)); //menu->setPosition(ccp(m_winSize.width / 2,m_winSize.height/ 4 - 10)); this->addChild(menu,kZOrderScore,kTagMenu); CCFiniteTimeAction* initFade = CCFadeTo::create(0.0f,0); CCFiniteTimeAction* initMove = CCMoveTo::create(0.0f,ccp(m_winSize.width / 2,50.0f - 10.0f)); CCSequence* initMix = CCSequence::createWithTwoActions(initFade,initMove); CCFiniteTimeAction* fade = CCFadeIn::create(1.5f); CCFiniteTimeAction* move = CCMoveBy::create(1.5f,ccp(0,10.0f)); CCSpawn* mix = CCSpawn::createWithTwoActions(fade,move); CCActionInterval* easeMix = CCEaseIn::create( CCSequence::createWithTwoActions(initMix,mix), 2.0f); menu->runAction(easeMix); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback) ); pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) ); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); /* Label */ CCLabelTTF* pLabel = CCLabelTTF::create("Colorful Touch-x", "Hevetica-BoldOblique", 100); CCSize size = CCDirector::sharedDirector()->getWinSize(); pLabel->setPosition( ccp(size.width / 2, size.height/2+100) ); this->addChild(pLabel, 1); /* Image */ CCSprite* pSprite = CCSprite::create("space_bg8.jpg"); pSprite->setPosition( ccp(size.width/2, size.height/2) ); this->addChild(pSprite, 0); /* Play the Game */ CCMenuItemFont::setFontName("Hevetica-BoldOblique"); CCMenuItemFont::setFontSize(50); CCMenuItemFont* item = CCMenuItemFont::create("play the game", this, menu_selector(HelloWorld::PlayTheGame)); CCMenu *menu = CCMenu::menuWithItem(item); menu->setPosition(CCPointMake(size.width/2, size.height/2-150)); CCFadeTo* fadeIn = CCFadeTo::actionWithDuration(1.0f, 127); CCFadeTo* fadeOut = CCFadeTo::actionWithDuration(1.0f, 255); CCSequence *pulseSequence = CCSequence::actionOneTwo(fadeIn, fadeOut); CCRepeatForever *repeat = CCRepeatForever::actionWithAction(pulseSequence); menu->runAction(repeat); this->addChild(menu,1); /* Back Particle */ BackParticle *backParticle = (BackParticle *)BackParticle::create(); this->addChild(backParticle); return true; }
void GameMain::setover() { CCMenu* pMenu = (CCMenu *)this->getChildByTag(25); pMenu->setVisible(true); pMenu->setEnabled(true); gameover->setVisible(true); gameover->setScale(0); pMenu->setScale(0); pMenu->runAction(CCScaleTo::create(0.5,1)); gameover->runAction(CCScaleTo::create(0.5,0.5)); isover = true; }
void LevelGame04::meCallback(CCObject* pSender) { isMenu++; if(isMenu == 3) { CCMenu *pmenu = (CCMenu *)getChildByTag(103); //CCFiniteTimeAction *scale = CCScaleTo::create(2.0f,2); CCFiniteTimeAction *blick=CCBlink::create(0.5f,10); //CCAction *action = CCSpawn::create(scale,blick,NULL); pmenu->runAction(blick); this->scheduleOnce(schedule_selector(LevelGame04::gamewin), 1.0f); } }
void MyBuildingCard::cancelDetail(cocos2d::CCNode *psender) { CCSprite* detailback = (CCSprite*)activeCard->getParent()->getChildByTag(detailBackTag); detailback->runAction(CCSequence::create(CCEaseInOut::create(CCMoveTo::create(0.2, ccp(detailback->getPosition().x,-detailback->getContentSize().height/2-100)),2),GXRemoveFromParentsAction::create(), NULL)); activeCard->runAction(CCSequence::create(CCDelayTime::create(0.2),CCEaseInOut::create(CCScaleTo::create(0.2, 1),2),NULL)); activeCard->runAction(CCSequence::create(CCDelayTime::create(0.2),CCEaseInOut::create(CCMoveTo::create(0.2, oriPosition),2),CCCallFunc::create(this,callfunc_selector(MyBuildingCard::reorderCall)),NULL)); CCMenu* grayMenu = (CCMenu*)activeCard->getParent()->getChildByTag(grayTag); grayMenu->runAction(CCSequence::create(CCDelayTime::create(0.2),CCFadeOut::create(0.2),GXRemoveFromParentsAction::create(),NULL)); }
void GameMainLayer::setOver() { //游戏结束 CCMenu *pMenu = (CCMenu *)this->getChildByTag(25); pMenu->setVisible(true); pMenu->setEnabled(true); pMenu->setScale(0); pMenu->runAction(CCScaleTo::create(0.5f, 1)); gameOver->setVisible(true); gameOver->setScale(0); gameOver->runAction(CCScaleTo::create(0.5f, 0.5f)); this->isOver = true; }
void LevelEndView::showResetButton() { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* up = CCSprite::spriteWithSpriteFrameName("button_reset.png"); CCSprite* down = CCSprite::spriteWithSpriteFrameName("button_reset_down.png"); ButtonSpriteMenuItem* button = ButtonSpriteMenuItem::itemFromNormalSprite(up, down, controller_, menu_selector(GameScene::restartGame)); CCMenu* menu = CCMenu::menuWithItem(button); menu->setPosition(ccp(310, -40)); addChild(menu); CCMoveBy* menuMoveUp = CCMoveBy::actionWithDuration(0.15, ccp(0, 80)); CCEaseBackOut* menuEase = CCEaseBackOut::actionWithAction(menuMoveUp); menu->runAction(menuEase); }
void LevelEndView::showLevelsButton() { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* up = CCSprite::spriteWithSpriteFrameName("button_back.png"); CCSprite* down = CCSprite::spriteWithSpriteFrameName("button_back_down.png"); ButtonSpriteMenuItem* button = ButtonSpriteMenuItem::itemFromNormalSprite(up, down, controller_, menu_selector(GameScene::levelSelect)); CCMenu* menu = CCMenu::menuWithItem(button); menu->setPosition(ccp(170, -40)); addChild(menu); CCMoveBy* menuMoveUp = CCMoveBy::actionWithDuration(0.15, ccp(0, 80)); CCEaseBackOut* menuEase = CCEaseBackOut::actionWithAction(menuMoveUp); CCCallFunc* showNext = CCCallFunc::actionWithTarget(this, callfunc_selector(LevelEndView::showResetButton)); CCSequence* sequence = CCSequence::actionOneTwo(menuEase, showNext); menu->runAction(sequence); }
void HelloWorld::endGame() { gameend = true; setTouchEnabled(false); if(this->bird->getPosition().y>320){ CCLog("%f",this->bird->getPosition().y); this->bird->dead(); } unscheduleUpdate(); unschedule(schedule_selector(HelloWorld::addBar)); //this->removeChild(this->bird); CCSprite *gameover = CCSprite::createWithSpriteFrameName("gameover.png"); gameover->setPosition(ccp(this->screenSize.width/2,this->screenSize.height/2)); gameover->runAction(CCMoveTo::create(0.5f,ccp(this->screenSize.width/2,this->screenSize.height/2+240))); addChild(gameover,1,1); //CCMenuItemImage *gameoverMenuItem = CCMenuItemImage::create("start.png","start.png",this,menu_selector(HelloWorld::gameEndCallback)); CCMenuItemSprite *gameoverMenuItem = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("start.png"), CCSprite::createWithSpriteFrameName("start.png"),this,menu_selector(HelloWorld::gameEndCallback)); CCMenu *menu = CCMenu::create(gameoverMenuItem, NULL); //b2BodyDef gameoverMenuItemDef; //gameoverMenuItemDef.type = b2_staticBody; ///gameoverMenuItemDef.position = b2Vec2(this->screenSize.width/2/RATIO,this->screenSize.height/2/RATIO); //b2Body *gameoverBody = this->world->CreateBody(&gameoverMenuItemDef); //menu->setPosition( CCPointZero ); menu->setPosition(ccp(this->screenSize.width/2,this->screenSize.height/2-100)); menu->setOpacity(0); CCActionInterval* move = CCMoveBy::create(0.5, ccp(0,100)); CCActionInterval* show = CCFadeIn::create(0.5); CCAction* action = CCSpawn::create( show, move, NULL); CCFiniteTimeAction* taction = CCSequence::create(CCDelayTime::create(0.3),action,NULL); menu->runAction(taction); addChild(menu,1,2); }
void LevelEndView::showButtons() { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* up = CCSprite::spriteWithSpriteFrameName("button_play.png"); CCSprite* down = CCSprite::spriteWithSpriteFrameName("button_play_down.png"); ButtonSpriteMenuItem* button = ButtonSpriteMenuItem::itemFromNormalSprite(up, down, controller_, menu_selector(GameScene::nextLevel)); CCMenu* menu = CCMenu::menuWithItem(button); menu->setPosition(ccp(screenSize.width/2, -40)); addChild(menu); CCMoveBy* menuMoveUp = CCMoveBy::actionWithDuration(0.15, ccp(0, 80)); CCEaseBackOut* menuEase = CCEaseBackOut::actionWithAction(menuMoveUp); CCCallFunc* showNext = CCCallFunc::actionWithTarget(this, callfunc_selector(LevelEndView::showLevelsButton)); CCCallFunc* showLevel = CCCallFunc::actionWithTarget(this, callfunc_selector(LevelEndView::showLevel)); CCFiniteTimeAction* sequence = CCSequence::actions(menuEase, showNext, showLevel, NULL); menu->runAction(sequence); }
bool JS_Result::CreateMenu() { bool bRet = false; do { s = CCDirector::sharedDirector()->getWinSize(); // OK 버튼 CCMenuItemImage* pDoneItem = CCMenuItemImage::create("common/game/button_ok.png", "common/game/button_ok_s.png", this, menu_selector(JS_Result::menuClickCallback)); pDoneItem->setTag(1); CCMenu* pMenu = CCMenu::create(); pMenu->addChild(pDoneItem); pMenu->setPosition(ccp(0, 0)); this->addChild(pMenu, 100); ////////////////////////////////////////////////////////////////////////////////////////// CCMoveTo* pMoveTo = NULL; CCFiniteTimeAction *actionDone = NULL; CCFiniteTimeAction *seq = NULL; #if(DEBUG_PLATFORM == CC_PLATFORM_ANDROID) pMoveTo = CCMoveTo::create(0.3f, ccp(0, 580)); #else pMoveTo = CCMoveTo::create(0.3f, ccp(0, 600)); #endif actionDone = CCCallFuncN::create( pMenu, NULL); seq = CCSequence::create(pMoveTo, actionDone, NULL); pMenu->runAction(seq); bRet = true; } while(0); return bRet; }