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 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; }
bool UserInputScene::init() { if (!CCLayer::init()) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile("welcome.plist","welcome.png"); CCSprite* bgSprite = CCSprite::create("login_2.png"); bgSprite->setAnchorPoint(CCPointZero); bgSprite->setPosition(ccp(origin.x,origin.y)); this->addChild(bgSprite,9); CCSprite* buttonSprite = CCSprite::create("start.png"); //buttonSprite->setAnchorPoint(CCPointZero); //buttonSprite->setScale(0.5f); //buttonSprite->setPosition(ccp(origin.x+visibleSize.width/2,origin.y)); //this->addChild(buttonSprite); SEL_MenuHandler startSelect= (SEL_MenuHandler)menu_selector(UserInputScene::startGame); CCMenuItemSprite* startMenu = CCMenuItemSprite::create(buttonSprite, buttonSprite, buttonSprite, this, startSelect ); CCMenu* menu = CCMenu::create(startMenu,NULL); menu->setPosition(ccp(origin.x+visibleSize.width/2,origin.y)); menu->setScale(0.5f); addChild(menu,10); CCSize editBoxSize = CCSizeMake(visibleSize.width - 100, 60); // top m_pEditName = CCEditBox::create(editBoxSize, CCScale9Sprite::create("username.png")); m_pEditName->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height*3/4)); m_pEditName->setFontSize(25); m_pEditName->setFontColor(ccRED); m_pEditName->setPlaceHolder("Name:"); m_pEditName->setPlaceholderFontColor(ccWHITE); m_pEditName->setMaxLength(8); m_pEditName->setReturnType(kKeyboardReturnTypeDone); m_pEditName->setDelegate(this); addChild(m_pEditName,10); m_pEditPassword = CCEditBox::create(editBoxSize, CCScale9Sprite::create("username.png")); m_pEditPassword->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2)); m_pEditPassword->setFontColor(ccGREEN); m_pEditPassword->setPlaceHolder("Password:"******"SelectSong1_1.json")); //ul->addWidget(widget); //Button* startBT = (Button*)ul->getWidgetByName("Button_28"); //startBT->addTouchEventListener(this,toucheventselector(UserInputScene::startGame)); ////////////////////////////////////////////////////////////////////////// return true; }
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); // 实现ground滚动和碰撞检测 this->scheduleUpdate(); // 初始化游戏状态 gameState=Welcome; }
void LevelSelectScene::menuStartCallback(CCObject *pSender) { CCMenu* levelSelectMenu = (CCMenu*)this->getChildByTag(tagLevelSelectMenuDialog); if(levelSelectMenu){ levelSelectMenu->setOpacity(128); levelSelectMenu->setEnabled(false); } CCMenuItemImage* targetLevelImage = (CCMenuItemImage*)pSender; m_level = targetLevelImage->getTag(); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCMenuItemImage* startMenuBG = CCMenuItemImage::create("logo_Info2.png","logo_Info2.png"); startMenuBG->setScale(0.7); startMenuBG->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.5)); startMenuBG->setEnabled(false); CCString* levelStr = CCString::createWithFormat("Lv:%d",m_level); CCSize pStartBGSize = startMenuBG->getContentSize(); CCLabelTTF* levelLabel; levelLabel = CCLabelTTF::create(levelStr->getCString(), "Copperplate", 60.0); levelLabel->setColor(ccc3(0, 0, 0)); levelLabel->setPosition(ccp(pStartBGSize.width * 0.5 ,pStartBGSize.height * 0.75)); startMenuBG->addChild(levelLabel); //ハイスコアを表示 CCString* bestStr = CCString::createWithFormat("MIN:%d BEST:%d",min_score[m_level-1],best_score[m_level-1]); CCLabelTTF* bestLabel; bestLabel = CCLabelTTF::create(bestStr->getCString(), "Copperplate", 60.0); bestLabel->setColor(ccc3(0, 0, 0)); bestLabel->setPosition(ccp(pStartBGSize.width * 0.5 ,pStartBGSize.height * 0.5)); startMenuBG->addChild(bestLabel); CCMenuItemImage* titleItem = CCMenuItemImage::create("button1.png","button1.png" ,this, menu_selector(LevelSelectScene::startGame)); titleItem->setPosition(ccp(winSize.width * 0.3, winSize.height * 0.42)); CCLabelTTF* titleLabel; titleLabel = CCLabelTTF::create("START", "Arial", 30.0); CCSize pTitleItemSize = titleItem->getContentSize(); titleLabel->setPosition(ccp(pTitleItemSize.width / 2 ,pTitleItemSize.height / 2)); titleItem->addChild(titleLabel); titleItem->setScale(0.8); CCMenuItemImage* returnGameItem = CCMenuItemImage::create("button2.png","button2.png" ,this, menu_selector(LevelSelectScene::hiddenStartMenu)); returnGameItem->setPosition(ccp(winSize.width * 0.7, winSize.height * 0.42)); CCLabelTTF* returnGameLabel; returnGameLabel = CCLabelTTF::create("CANCEL", "Arial", 30.0); CCSize pReturnGameSize = returnGameItem->getContentSize(); returnGameLabel->setPosition(ccp(pReturnGameSize.width / 2 ,pReturnGameSize.height / 2)); returnGameItem->addChild(returnGameLabel); returnGameItem->setScale(0.8); CCMenu* resumeDialog = CCMenu::create(startMenuBG, titleItem, returnGameItem, NULL); resumeDialog->setPosition(CCPointZero); resumeDialog->setTag(tagStartMenuDialog); resumeDialog->setScale(winSize.width/640); this->addChild(resumeDialog); }
bool Level::init() { if (!CCLayer::init()) { return false; } /*预加载音效*/ SimpleAudioEngine::sharedEngine()->preloadEffect("confirm.mp3"); /*添加背景*/ CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSprite* spBackGround = CCSprite::create("levelBackground.png"); spBackGround->setPosition(ccp(size.width*0.5, size.height*0.5)); addChild(spBackGround); /*创建图片菜单项*/ CCMenuItemImage *item1 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel1)); CCMenuItemImage *item2 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel2)); CCMenuItemImage *item3 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel3)); CCMenuItemImage *item4 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel4)); CCMenuItemImage *item5 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel5)); /*创建返回菜单项*/ CCMenuItemImage *itemBack = CCMenuItemImage::create("display_back.png", "display_back.png", this, menu_selector(Level::backToMenu));; /*设置菜单项大小*/ item1->setScale(0.45); item2->setScale(0.45); item3->setScale(0.45); item4->setScale(0.45); item5->setScale(0.45); /*创建菜单*/ CCMenu* menu1 = CCMenu::create(item1, item2, item3, item4, item5, NULL); menu1->setPosition(ccp(size.width * 0.5, size.height * 0.55)); menu1->alignItemsHorizontallyWithPadding(70); CCMenu* menuBack = CCMenu::create(itemBack, NULL); addChild(menuBack); menuBack->setPosition(ccp(size.width * 0.36, size.height * 0.05)); menuBack->setScale(0.7); menuBack->setColor(ccc3(0, 32, 240)); /*创建图片菜单项*/ CCMenuItemImage *item6 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel6)); CCMenuItemImage *item7 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel7)); CCMenuItemImage *item8 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel8)); CCMenuItemImage *item9 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel9)); CCMenuItemImage *item10 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel10)); /*设置菜单项大小*/ item6->setScale(0.45); item7->setScale(0.45); item8->setScale(0.45); item9->setScale(0.45); item10->setScale(0.45); /*创建菜单*/ CCMenu* menu2 = CCMenu::create(item6, item7, item8, item9, item10, NULL); menu2->setPosition(ccp(size.width * 1.5, size.height * 0.55)); menu2->alignItemsHorizontallyWithPadding(70); /*-----------------------*/ /*创建图片菜单项*/ CCMenuItemImage *item11 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel11)); CCMenuItemImage *item12 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel12)); CCMenuItemImage *item13 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel13)); CCMenuItemImage *item14 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel14)); CCMenuItemImage *item15 = CCMenuItemImage::create("level_normal.png", "level_selected.png", this, menu_selector(Level::chooseLevel15)); /*设置菜单项大小*/ item11->setScale(0.45); item12->setScale(0.45); item13->setScale(0.45); item14->setScale(0.45); item15->setScale(0.45); /*创建菜单*/ CCMenu* menu3 = CCMenu::create(item11, item12, item13, item14, item15, NULL); menu3->setPosition(ccp(size.width * 2.5, size.height * 0.55)); menu3->alignItemsHorizontallyWithPadding(70); /*添加关卡锁*/ lock2 = CCSprite::create("lock.png"); lock3 = CCSprite::create("lock.png"); lock4 = CCSprite::create("lock.png"); lock5 = CCSprite::create("lock.png"); lock6 = CCSprite::create("lock.png"); lock7 = CCSprite::create("lock.png"); lock8 = CCSprite::create("lock.png"); lock9 = CCSprite::create("lock.png"); lock10 = CCSprite::create("lock.png"); lock11 = CCSprite::create("lock.png"); lock12 = CCSprite::create("lock.png"); lock13 = CCSprite::create("lock.png"); lock14 = CCSprite::create("lock.png"); lock15 = CCSprite::create("lock.png"); item2->addChild(lock2); item3->addChild(lock3); item4->addChild(lock4); item5->addChild(lock5); item6->addChild(lock6); item7->addChild(lock7); item8->addChild(lock8); item9->addChild(lock9); item10->addChild(lock10); item11->addChild(lock11); item12->addChild(lock12); item13->addChild(lock13); item14->addChild(lock14); item15->addChild(lock15); addLock(); //创建层容器 CCLayer * containLayer = CCLayer::create(); containLayer->addChild(menu1); containLayer->addChild(menu2); containLayer->addChild(menu3); containLayer->setContentSize(CCSizeMake(size.width * 4, size.height)); /*添加关数*/ CCLabelTTF* level1 = CCLabelTTF::create("1st", "Georgia-Bold", 45); CCLabelTTF* level2 = CCLabelTTF::create("2nd", "Georgia-Bold", 45); CCLabelTTF* level3 = CCLabelTTF::create("3rd", "Georgia-Bold", 45); CCLabelTTF* level4 = CCLabelTTF::create("4th", "Georgia-Bold", 45); CCLabelTTF* level5 = CCLabelTTF::create("5th", "Georgia-Bold", 45); CCLabelTTF* level6 = CCLabelTTF::create("6th", "Georgia-Bold", 45); CCLabelTTF* level7 = CCLabelTTF::create("7th", "Georgia-Bold", 45); CCLabelTTF* level8 = CCLabelTTF::create("8th", "Georgia-Bold", 45); CCLabelTTF* level9 = CCLabelTTF::create("9th", "Georgia-Bold", 45); CCLabelTTF* level10 = CCLabelTTF::create("10th", "Georgia-Bold", 45); CCLabelTTF* level11 = CCLabelTTF::create("11th", "Georgia-Bold", 45); CCLabelTTF* level12 = CCLabelTTF::create("12th", "Georgia-Bold", 45); CCLabelTTF* level13 = CCLabelTTF::create("13th", "Georgia-Bold", 45); CCLabelTTF* level14 = CCLabelTTF::create("14th", "Georgia-Bold", 45); CCLabelTTF* level15 = CCLabelTTF::create("15th", "Georgia-Bold", 45); containLayer->addChild(level1); containLayer->addChild(level2); containLayer->addChild(level3); containLayer->addChild(level4); containLayer->addChild(level5); containLayer->addChild(level6); containLayer->addChild(level7); containLayer->addChild(level8); containLayer->addChild(level9); containLayer->addChild(level10); containLayer->addChild(level11); containLayer->addChild(level12); containLayer->addChild(level13); containLayer->addChild(level14); containLayer->addChild(level15); level1->setPosition(ccp(size.width * 0.18, size.height * 0.4)); level2->setPosition(ccp(size.width * 0.34, size.height * 0.4)); level3->setPosition(ccp(size.width * 0.5, size.height * 0.4)); level4->setPosition(ccp(size.width * 0.657, size.height * 0.4)); level5->setPosition(ccp(size.width * 0.82, size.height * 0.4)); level6->setPosition(ccp(size.width * 1.18, size.height * 0.4)); level7->setPosition(ccp(size.width * 1.34, size.height * 0.4)); level8->setPosition(ccp(size.width * 1.5, size.height * 0.4)); level9->setPosition(ccp(size.width * 1.657, size.height * 0.4)); level10->setPosition(ccp(size.width * 1.82, size.height * 0.4)); level11->setPosition(ccp(size.width * 2.18, size.height * 0.4)); level12->setPosition(ccp(size.width * 2.34, size.height * 0.4)); level13->setPosition(ccp(size.width * 2.5, size.height * 0.4)); level14->setPosition(ccp(size.width * 2.657, size.height * 0.4)); level15->setPosition(ccp(size.width * 2.82, size.height * 0.4)); /*创建滚动视图*/ scrollView = CCScrollView::create(CCSizeMake(size.width*3, size.height)); addChild(scrollView); scrollView->setBounceable(false);//设置scrollview有弹跳效果(默认为true) scrollView->setViewSize(CCSizeMake(size.width*2, size.height));//设置scrollView尺寸 scrollView->setContainer(containLayer);//设置容器 scrollView->getViewSize();//获取视图尺寸 scrollView->setTouchEnabled(true);//开启监听多触点 scrollView->setDelegate(this);//注册监听 return true; }