// on "init" you need to initialize your instance bool Title::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } srand(time(NULL)); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("panels.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("title.plist"); SimpleAudioEngine::sharedEngine()->preloadEffect("menu.wav"); SimpleAudioEngine::sharedEngine()->preloadEffect("pon.wav"); SimpleAudioEngine::sharedEngine()->preloadEffect("shupiin.wav"); //CCLabelTTF* titleLabel = CCLabelTTF::create("Hello", "arial", 20); //titleLabel->setPosition(CCPoint(visibleSize.width / 2, visibleSize.height / 2)); //this->addChild(titleLabel); CCSprite* titleBackground = CCSprite::createWithSpriteFrameName("title.png"); titleBackground->setAnchorPoint(CCPoint(0.5, 0.5)); titleBackground->setScale(visibleSize.width / 640); titleBackground->setPosition(CCPoint(visibleSize.width / 2, visibleSize.height / 2)); this->addChild(titleBackground, 1); CCMenuItemFont* gameMainFont = CCMenuItemFont::create("GAME START", this, menu_selector(Title::gameMainAction)); gameMainFont->setFontNameObj(MISAKI_FONT); CCMenuItemLabel *gameMainButton = gameMainFont; gameMainButton->setColor(ccBLACK); CCMenuItemFont* rankingFont = CCMenuItemFont::create("RANKING", this, menu_selector(Title::rankingAction)); rankingFont->setFontNameObj(MISAKI_FONT); CCMenuItemLabel *rankingButton =rankingFont; rankingButton->setColor(ccBLACK); //CCMenuItemLabel *gamecenterButton = CCMenuItemFont::create("GameCenterLogin", this, menu_selector(Title::login)); CCMenuItemFont* creditFont = CCMenuItemFont::create("CREDIT", this, menu_selector(Title::creditAction)); creditFont->setFontNameObj(MISAKI_FONT); CCMenuItemLabel *creditButton =creditFont; creditButton->setColor(ccBLACK); //CCMenu *menu = CCMenu::createWithItems(gameMainButton, NULL); CCMenu *menu = CCMenu::create(gameMainButton, rankingButton, creditButton, NULL); menu->setPosition(ccp(visibleSize.width/2, visibleSize.height/4)); menu->alignItemsVertically(); this->addChild(menu, 2); CCGATracker::sendView("Title"); setTouchEnabled(true); this->schedule(schedule_selector(Title::update)); return true; }
bool GameMenu::init() { if ( !CCLayer::init() ) { return false; } CCSize size = CCDirector::sharedDirector()->getWinSize(); CCMenuItemFont *pCloseItem = CCMenuItemFont::create("Quit Game", this, menu_selector(GameMenu::menuCloseCallback) ); pCloseItem->setPosition( ccp(size.width/2, size.height/8) ); pCloseItem->setFontSizeObj(25); pCloseItem->setFontNameObj("Georgia-Bold"); CCMenuItemFont* pStartItem = CCMenuItemFont::create("Start Game", this, menu_selector(GameMenu::menuStartCallback) ); pStartItem->setPosition(ccp(size.width/2,size.height/4)); pStartItem->setFontSizeObj(40); pStartItem->setFontNameObj("Georgia-Bold"); CCMenuItemFont* pNextItem = CCMenuItemFont::create(">", this, menu_selector(GameMenu::selectNext) ); pNextItem->setPosition(ccp(size.width/3*2,size.height/5*2)); pNextItem->setFontSizeObj(80); pNextItem->setFontNameObj("Georgia-Bold"); CCMenuItemFont* pBackItem = CCMenuItemFont::create("<", this, menu_selector(GameMenu::selectBack) ); pBackItem->setPosition(ccp(size.width/3,size.height/5*2)); pBackItem->setFontSizeObj(80); pBackItem->setFontNameObj("Georgia-Bold"); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, pStartItem, pNextItem, pBackItem, NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); CCSprite* pGameName = CCSprite::create("BattleCity.png"); pGameName->setScale(2.0f); pGameName->setPosition(ccp(size.width/2,size.height/3*2)); this->addChild(pGameName,1); CCLabelTTF *LevelLabel = CCLabelTTF::create("Level 1", "Georgia-Bold", 55); LevelLabel->setString(CCString::createWithFormat("Level %d", m_level)->getCString()); LevelLabel->setPosition(ccp(size.width/2,size.height/5*2)); this->addChild(LevelLabel,2,888); return true; }