예제 #1
0
bool MainMenu::init()
{
    if(CCLayer::init())
    {
        CCSprite *bg = CCSprite::create("bg.png");
        bg->setPosition(ccp(240, 160));
        this->addChild(bg);
        
        CCMenuItemFont *item1 = CCMenuItemFont::create("interval");
        CCMenuItemFont *item2 = CCMenuItemFont::create("intant");
        CCMenuItemFont *item3 = CCMenuItemFont::create("speed");
        CCMenuItemFont *item4 = CCMenuItemFont::create("follow");
        CCMenuItemFont *item5 = CCMenuItemFont::create("manager");
        
        item1->setTarget(this, menu_selector(MainMenu::actionIntervalCallBack));
        item2->setTarget(this, menu_selector(MainMenu::actionIntantCallBack));
        item3->setTarget(this, menu_selector(MainMenu::actionSpeedCallBack));
        item4->setTarget(this, menu_selector(MainMenu::actionFollowCallBack));
        item5->setTarget(this, menu_selector(MainMenu::actionManagerCallBack));
        
        CCMenu *menu = CCMenu::create(item1,item2,item3,item4,item5,NULL);
        menu->setColor(ccc3(0, 255, 0));
        menu->alignItemsInColumns(1,2,2);
        menu->setPosition(ccp(240,160));
        this->addChild(menu);
        return true;
    }
    return false;
}
예제 #2
0
bool VictoryScene::init()
{
	bool bRet = false;
    do
    {
        CCDirector * pDirector;
        CC_BREAK_IF( ! (pDirector = CCDirector::sharedDirector()) );
        this->setContentSize(pDirector->getWinSize());
        CCSprite* pSprite = CCSprite::create("victory.png");
        
        // position the sprite on the center of the screen
        pSprite->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width * 0.5 , CCDirector::sharedDirector()->getVisibleSize().height * 0.5));
        // add the sprite as a child to this layer
        addChild(pSprite, -1);
        
		//create menu for game victory
		CCMenuItemFont* backMenu = CCMenuItemFont::create("Back To Menu",this,menu_selector(GameScene::menuPopSceneCallback));
		CCMenuItemFont* exit = CCMenuItemFont::create("Exit",this,menu_selector(GameOverScene::menuCloseCallback));

		CCMenu* menu;
       /* if (pItem!= NULL)
        {
            menu = CCMenu::create(pItem,backMenu,exit,NULL);
        }
		else
		{*/
			menu = CCMenu::create(backMenu,exit,NULL);
		//}
		menu->alignItemsVertically();
		menu->setColor(ccc3(0,0,0));
		addChild(menu,3);

        
        // success
        bRet = true;
    } while (0);
    return bRet;
}
예제 #3
0
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;
}
예제 #4
0
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;
}