void TetrisGameLayer::startGame(){ G_current_HandleType = new LongBlock_Type(); G_current_HandleType->init(); CCSize size = CCDirector::sharedDirector()->getWinSize(); //控制按钮// CCMenuItemImage * left = CCMenuItemImage::create("left.png", "left.png"); left->setTarget(this, menu_selector(TetrisGameLayer::leftButtonPressed)); left->setScale(0.5); CCMenuItemImage * right = CCMenuItemImage::create("right.png", "right.png"); right->setTarget(this, menu_selector(TetrisGameLayer::rightButtonPressed)); left->setAnchorPoint(ccp(0, 0)); right->setAnchorPoint(ccp(0, 0)); right->setScale(0.5); right->setPosition(ccp(size.width/2+size.width/4, 0)); CCMenuItemImage * down = CCMenuItemImage::create("down.png", "down.png"); down->setTarget(this, menu_selector(TetrisGameLayer::downButtonPressed)); down->setAnchorPoint(ccp(0,0)); down->setScale(0.5); down->setPosition(ccp(size.width/2 -100,0)); down->setOpacity(0.7*255); CCMenu * menu = CCMenu::create(left,down,right, NULL); menu->setAnchorPoint(ccp(0, 0)); menu->setPosition(ccp(0, 0)); this->addChild(menu); }
void NetworkUDP::onEnter() { NetworkDemo::onEnter(); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); // to test this sample, find udp_server.py in server folder, run it with python // you need install greenlet and gevent CCMenuItemLabel* item1 = CCMenuItemLabel::create(CCLabelTTF::create("Send Hello", "Helvetica", 40 / CC_CONTENT_SCALE_FACTOR()), this, menu_selector(NetworkUDP::onSendClicked)); item1->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); CCMenu* menu = CCMenu::create(item1, NULL); menu->setAnchorPoint(CCPointZero); menu->setPosition(CCPointZero); addChild(menu); // received content m_recv = CCLabelTTF::create("", "Helvetica", 20 / CC_CONTENT_SCALE_FACTOR()); m_recv->setPosition(ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 5)); addChild(m_recv); // change ip to your server // registerCallback must be invoked before createSocket otherwise bound event is lost m_hub = CCUDPSocketHub::create(); m_hub->registerCallback(1, this); m_hub->createSocket("192.168.1.104", 9000, 1); CC_SAFE_RETAIN(m_hub); }
void NewsScene::createListView() { // CCSize size = CCSize(750, 400); CCSize size = CCDirector::sharedDirector()->getWinSize(); CCLayerColor * fundo = CCLayerColor::create(ccc4(255, 255, 255, 255), size.width, size.height); fundo->setAnchorPoint(ccp(0,0)); fundo->setPosition(ccp(0, 0)); this->addChild(fundo,10); // CCLayerColor * header = CCLayerColor::create(ccc4(200, 200, 200, 255), size.width, 80); // header->setAnchorPoint(ccp(0,0)); // header->setPosition(ccp(0, size.height -80)); // fundo->addChild(header); CCSprite *sprHeader; sprHeader = CCSprite::create("Header_Blue.png"); sprHeader->setAnchorPoint(ccp(0,0)); sprHeader->setScale(1); sprHeader->setPosition(ccp(0, size.height -90)); this->addChild(sprHeader,100); CCSprite *sprTitle; sprTitle = CCSprite::create("tit_informacoes.png"); sprTitle->setAnchorPoint(ccp(0,0)); sprTitle->setScale(1); sprTitle->setPosition(ccp(110, size.height -50)); this->addChild(sprTitle,101); CCMenu* menu = CCMenu::create(); CCSprite *spriteDefault = CCSprite::create("Seta1.png"); CCSprite *spriteSelected = CCSprite::create("Seta2.png"); CCMenuItemSprite *item = CCMenuItemSprite::create(spriteDefault, spriteSelected, this, menu_selector(NewsScene::btnBack)); item->setAnchorPoint(ccp(0, 0)); item->setPosition(ccp(0, size.height -90)); menu->addChild(item, 0, 100); menu->setPosition(ccp(10,30)); menu->setAnchorPoint(ccp(0,0)); this->addChild(menu,102); list = CCListView::create(CCListViewModeVertical); list = cocos2d::extension::CCListView::create(CCListViewModeVertical); list->setDelegate(this); list->setContentSize(CCSize(size.width, size.height-70)); list->setAnchorPoint(ccp(0,0)); list->setPosition(ccp(0, 0)); list->setColor(ccc3(50, 50, 50)); list->setSeparatorStyle(CCListViewCellSeparatorStyleNone); fundo->addChild(list); this->loading = new AnimatedSprite("loader_einstein1.png"); this->loading->addAnimation(AnimatedSprite::animationWithFile("loader_einstein", 24, 0.030f), "anim");//frame_count this->addChild(this->loading,999); this->loading->runAnimation("anim",true, true); this->loading->setAnchorPoint(ccp(0.5f, 0.5f)); this->loading->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2, CCDirector::sharedDirector()->getWinSize().height/2 - 30)); this->loading->setVisible(true); }
bool HelpScene::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } setKeypadEnabled(true); LayoutManager *layoutManager = LayoutManager::getInstance(); CCRect visibleRect = layoutManager->getVisibleRect(); CCDirector *director = CCDirector::sharedDirector(); m_Background = CCSprite::create("help.png"); m_Background->retain(); m_Background->setPosition(director->getVisibleOrigin() + director->getVisibleSize() / 2); addChild(m_Background); CCMenuItemImage *pBack = CCMenuItemImage::create("back.png", NULL, this, menu_selector(HelpScene::backCallback)); pBack->setAnchorPoint(CCPointZero); pBack->setPosition(ccp(visibleRect.origin.x + 18, visibleRect.origin.y + 12)); CCMenu *pMenu = CCMenu::create(pBack, NULL); pMenu->setAnchorPoint(CCPointZero); pMenu->setPosition(CCPointZero); addChild(pMenu); return true; }
CCLayer* GameScene::showTimerBoarder() { CCLayer* board = CCLayer::create(); CCSprite* boardBG = CCSprite::create("header.png"); boardBG->setPosition(ccp(320,0)); boardBG->setAnchorPoint(ccp(0.5f,0)); board->addChild(boardBG); CCMenuItemImage* imageItem = CCMenuItemImage::create("btn-pause.png","btn-pause-down.png", this,menu_selector(GameScene::restartScene)); imageItem->setAnchorPoint(ccp(0,1)); CCMenu* menu = CCMenu::create(imageItem,NULL); menu->setAnchorPoint(ccp(0,1)); menu->setPosition(ccp(0,158)); pr = CCProgressTimer::create(CCSprite::create("timer.png")); pr->setPosition(ccp(320,16)); pr->setAnchorPoint(ccp(0.5,0)); pr->setPercentage(1.0f); pr->setType(kCCProgressTimerTypeBar); pr->setMidpoint(ccp(1,0)); pr->setBarChangeRate(ccp(1,0)); this->schedule(schedule_selector(GameScene::countTime),1.0f); scoreTxt = CCLabelBMFont::create("0","fonts/scorefont.fnt"); scoreTxt->setAnchorPoint(ccp(1,0.5f)); scoreTxt->setScale(1.0f); scoreTxt->setAlignment(kCCTextAlignmentRight); scoreTxt->setPosition(ccp(640,110)); board->addChild(scoreTxt,10); board->addChild(pr); board->addChild(menu); return board; }
void BYGameScene::loadUI() { CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile("ui.plist", "ui.png"); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); /// pause button CCSprite* btnNormalSprite = CCSprite::createWithSpriteFrameName("pause.png"); CCMenuItemSprite *pauseMenuItem = CCMenuItemSprite::create(btnNormalSprite, btnNormalSprite, this, menu_selector(BYGameScene::pauseButtonHandler)); /// 2 labels for goals ccColor3B color = ccc3(220, 70, 20); /// red color _labelBotPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40); _labelBotPlayerGoalsScored->setColor(color); CCMenuItemLabel *labelBot = CCMenuItemLabel::create(_labelBotPlayerGoalsScored, NULL, NULL); labelBot->setEnabled(false); _labelTopPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40); _labelTopPlayerGoalsScored->setColor(color); CCMenuItemLabel *labelTop = CCMenuItemLabel::create(_labelTopPlayerGoalsScored, NULL, NULL); labelTop->setEnabled(false); /// CCMenu doesnt support anchorPoint as of 0x00020003 version CCMenu *menu = CCMenu::create(labelTop, pauseMenuItem, labelBot, NULL); menu->alignItemsHorizontallyWithPadding(5); menu->setAnchorPoint(CCPointMake(0, 0)); menu->setPosition(CCPointMake(winSize.width - pauseMenuItem->getContentSize().width / 2, winSize.height / 2)); menu->setRotation(90); this->addChild(menu); }
// on "init" you need to initialize your instance bool GameScene::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } setTouchEnabled(true); setKeypadEnabled(true); m_GroundPosY = 187/* ground position in bg1.jpg(bg2.jpg) */ - m_VisibleOrigin.y; m_pBackground1 = CCSprite::create("bg1.jpg"); m_pBackground1->retain(); m_pBackground1->setPosition(m_VisibleOrigin + m_VisibleSize / 2); addChild(m_pBackground1); m_pBackground2 = CCSprite::create("bg1.jpg"); m_pBackground2->retain(); m_pBackground2->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width * 1.5f, m_VisibleOrigin.y + m_VisibleSize.height * 0.5f)); addChild(m_pBackground2); m_ScoreLabel = CCLabelAtlas::create(CCString::createWithFormat("%d", m_CurrentScore)->getCString(), "fonts/font1.png", 56, 72, '0'); m_ScoreLabel->retain(); m_ScoreLabel->setZOrder(1); m_ScoreLabel->setAnchorPoint(ccp(0.5, 0.5)); m_ScoreLabel->setScale(0.85f); m_ScoreLabel->setPosition(m_VisibleOrigin.x + m_VisibleSize.width / 2, m_VisibleOrigin.y + m_VisibleSize.height * 0.86125); addChild(m_ScoreLabel); m_Title = CCSprite::create("title_ready.png"); m_Title->retain(); m_Title->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 2, m_VisibleOrigin.x + m_VisibleSize.height * 0.725f)); addChild(m_Title); m_Hint = CCSprite::create("hint.png"); m_Hint->retain(); m_Hint->setScale(0.76f); m_Hint->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 2, m_VisibleOrigin.y + m_VisibleSize.height / 2)); addChild(m_Hint); m_pPause = LGMenuItemImage::create("pause.png", NULL, this, menu_selector(GameScene::pauseCallback)); m_pPause->retain(); m_pPause->setVisible(false); m_pPause->setScale(0.85f); m_pPause->setPosition(m_VisibleOrigin.x + 43, m_VisibleOrigin.y + m_VisibleSize.height - 41); CCMenu *pMenu = CCMenu::create(m_pPause, NULL); pMenu->setZOrder(3); pMenu->setAnchorPoint(CCPointZero); pMenu->setPosition(CCPointZero); addChild(pMenu); addPig(); scheduleUpdate(); schedule(schedule_selector(GameScene::updatePillar), 0.1f, kCCRepeatForever, 0); return true; }
void GameScene::showGameEnd() { gameLayer->showGameEnd(); timeBoard->runAction(CCMoveTo::create(0.3f,ccp(0,1136+158))); CCLayer* gameEndLayer = CCLayer::create(); CCSprite* bgSprite = CCSprite::create("fade.png"); scoreTxt = CCLabelBMFont::create(GameData::shareData()->getScoreString(),"fonts/scorefont.fnt"); scoreTxt->setPosition(ccp(320,700)); scoreTxt->setScale(0.0f); CCScaleTo* scaleTo = CCScaleTo::create(0.9f,2.5f); CCEaseElasticInOut* scoreEff = CCEaseElasticInOut::create(scaleTo); scoreTxt->runAction(scoreEff); if(!scoreTxt->getParent()) gameEndLayer->addChild(scoreTxt); bgSprite->setAnchorPoint(ccp(0,0)); gameEndLayer->addChild(bgSprite); CCLabelTTF* txt = CCLabelTTF::create("Game End","fonts/Marker Felt.ttf",40.0f); txt->setPosition(ccp(320,568)); gameEndLayer->addChild(txt); CCMenuItemImage* imageItem = CCMenuItemImage::create("CloseNormal.png","CLoseSelected.png", this,menu_selector(GameScene::backToMainMenu)); CCMenu* menu = CCMenu::create(imageItem,NULL); menu->setAnchorPoint(ccp(0,0)); menu->setPosition(ccp(320,300)); imageItem->setScale(3.0f); gameEndLayer->addChild(menu); this->addChild(gameEndLayer,100,this->getChildrenCount()); }
void RPGStartSceneLayer::showMainMenu() { CCMenu *mainMenu = CCMenu::create(); mainMenu->setAnchorPoint(CCPointZero); mainMenu->setPosition(CCPointZero); mainMenu->setTag(kRPGStartSceneLayerTagMainMenu); this->addChild(mainMenu); CCString *menuStartStr = (CCString*)this->m_stringList->objectForKey("mainmenu_start"); CCLabelTTF *menuStartLabel = CCLabelTTF::create(OzgCCUtility::generalString(menuStartStr->getCString()).c_str(), "FZCuYuan-M03S", 28, CCSizeMake(120, 40), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); CCString *menuRestartStr = (CCString*)this->m_stringList->objectForKey("mainmenu_restart"); CCLabelTTF *menuRestartLabel = CCLabelTTF::create(OzgCCUtility::generalString(menuRestartStr->getCString()).c_str(), "FZCuYuan-M03S", 28, CCSizeMake(120, 40), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); CCString *menuSettingsStr = (CCString*)this->m_stringList->objectForKey("mainmenu_settings"); CCLabelTTF *menuSettingsLabel = CCLabelTTF::create(OzgCCUtility::generalString(menuSettingsStr->getCString()).c_str(), "FZCuYuan-M03S", 28, CCSizeMake(120, 40), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); CCMenuItemLabel *menuStart = CCMenuItemLabel::create(menuStartLabel, this, menu_selector(RPGStartSceneLayer::onMenu)); menuStart->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2, 230)); menuStart->setTag(kRPGStartSceneLayerTagMainMenuItemStart); mainMenu->addChild(menuStart); CCMenuItemLabel *menuRestart = CCMenuItemLabel::create(menuRestartLabel, this, menu_selector(RPGStartSceneLayer::onMenu)); menuRestart->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2, 170)); menuRestart->setTag(kRPGStartSceneLayerTagMainMenuItemRestart); mainMenu->addChild(menuRestart); CCMenuItemLabel *menuSettings = CCMenuItemLabel::create(menuSettingsLabel, this, menu_selector(RPGStartSceneLayer::onMenu)); menuSettings->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2, 110)); menuSettings->setTag(kRPGStartSceneLayerTagMainMenuItemSettings); mainMenu->addChild(menuSettings); }
bool StatusMenu::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLayerColor* layer = CCLayerColor::create( ccc4(135, 135 , 135, 255)); layer->ignoreAnchorPointForPosition(false); layer->setPosition( CCPointMake(s.width/2, s.height/2) ); addChild(layer, 0); CCMenuItemImage *closebutton = CCMenuItemImage::create("close.png", "close_down.png", this, menu_selector(StatusMenu::CloseCallback)); CCMenuItemImage *itembutton = CCMenuItemImage::create("package.png", "package_down.png", this, menu_selector(StatusMenu::ItemMenuCallback)); CCMenuItemImage *charabutton = CCMenuItemImage::create("chara.png", "chara_down.png", this, menu_selector(StatusMenu::CharacterMenuCallback)); closebutton->setPosition(ccp(-250, 50)); itembutton->setPosition(ccp(-250, 105)); charabutton->setPosition(ccp(-250, 160)); CCMenu *menu = CCMenu::create(charabutton,itembutton,closebutton,NULL); addChild(menu,1); CCSprite *charabox = CCSprite::create("menu_bg_all.png"); charabox->setPosition(ccp(450, s.height/2)); addChild(charabox,1,12); CCSprite *itembox = CCSprite::create("item_bg_all.png"); itembox->setPosition(ccp(450, s.height/2)); addChild(itembox,1,13); CCMenu *itemmenu = CCMenu::create(); for (int i=0; i<player->items.size(); i++) { switch (player->items[i]) { case 4:{ CCMenuItemLabel *item = CCMenuItemLabel::create(CCLabelTTF::create("手电筒 X1", "AR PLMingU20 Light", 24)); itemmenu->addChild(item, i+1, i+1); break; } case 6:{ CCMenuItemLabel *item = CCMenuItemLabel::create(CCLabelTTF::create("水果刀 X1", "AR PLMingU20 Light", 24)); itemmenu->addChild(item, i+1, i+1); break; } case 12:{ CCMenuItemLabel *item = CCMenuItemLabel::create(CCLabelTTF::create("钥匙 X1", "AR PLMingU20 Light", 24)); itemmenu->addChild(item, i+1, i+1); break; } default: break; } } itemmenu->setAnchorPoint(ccp(0, 1)); itemmenu->alignItemsVertically(); itemmenu->setPosition(itembox->getPositionX()-300,itembox->getPositionY()+130); itembox->addChild(itemmenu); CharacterMenuCallback(NULL); return true; }
void GameLayer::configureGame(GameLevel gameLevel) { _gameLevel = gameLevel; _accelVelocity = CCPointZero; CCPoint visOrigin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSize visSize = CCDirector::sharedDirector()->getVisibleSize(); _menuPause = CCMenuItemImage::create("pause_off.png", "pause.png", this, menu_selector(GameLayer::pauseGame)); _menuPause->setVisible(false); _menuPause->setPositionX(visOrigin.x + _menuPause->getContentSize().width * 0.9f); _menuPause->setPositionY(visOrigin.y + visSize.height - _menuPause->getContentSize().width * 0.6f); CCMenu* menu = CCMenu::create(); menu->setAnchorPoint(ccp(0, 0)); menu->setPosition(CCPointZero); menu->addChild(_menuPause); addChild(menu, kDeepPauseLayer); setTouchEnabled(true); _worldSpeed = START_WORLD_SPEED; _minDistanceObstaclesX = MIN_DISTANCE_OBSTACLES; if(_gameLevel == kGameLevelEasy) { _minDistanceObstaclesX *= 2.0f; // 1.0 _worldSpeed *= 1.0f; // 0.9 _vectorMap.insert(_vectorMap.begin(), easyMap, easyMap + sizeof(easyMap) / sizeof(int)); } else if(_gameLevel == kGameLevelNormal) { _minDistanceObstaclesX *= 1.3f; // 0.9 _worldSpeed *= 1.7f; // 1.8 _vectorMap.insert(_vectorMap.begin(), normalMap, normalMap + sizeof(normalMap) / sizeof(int)); } else if(_gameLevel == kGameLevelHard) { _minDistanceObstaclesX *= 1.0f; // 0.7 _worldSpeed *= 2.2f; // 2.4 _vectorMap.insert(_vectorMap.begin(), hardMap, hardMap + sizeof(hardMap) / sizeof(int)); } _itemMap = 0; _gameState = kGameStarting; _pause = false; _gameOver = false; _createPlayer(); _initElements(); }
bool HomeScene::init() { // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSprite* bgSpr = CCSprite::create("home_bg.png"); bgSpr->setAnchorPoint(ccp(0, 0)); bgSpr->setPosition( ccp(0, size.height-960) ); this->addChild(bgSpr, -1, 0); HomeLayer* layer = new HomeLayer(); layer->initWithDelegate(this); this->addChild(layer); //下导航区域 CCMenuItemImage *bu01 = CCMenuItemImage::create("zhuye.png", "zhuye.png", this, menu_selector(HomeScene::menuItemCallBack)); bu01->setTag(1); bu01->setPosition(ccp(60, 0)); CCMenuItemImage *bu02 = CCMenuItemImage::create("chengshi.png", "chengshi.png", this, menu_selector(HomeScene::menuItemCallBack)); bu02->setTag(2); bu02->setPosition(ccp(165, 0)); CCMenuItemImage *bu03 = CCMenuItemImage::create("fuben.png", "fuben.png", this, menu_selector(HomeScene::menuItemCallBack)); bu03->setTag(3); bu03->setPosition(ccp(270, 0)); CCMenuItemImage *bu04 = CCMenuItemImage::create("huodong.png", "huodong.png", this, menu_selector(HomeScene::menuItemCallBack)); bu04->setTag(4); bu04->setPosition(ccp(375, 0)); CCMenuItemImage *bu05 = CCMenuItemImage::create("beibao.png", "beibao.png", this, menu_selector(HomeScene::menuItemCallBack)); bu05->setTag(5); bu05->setPosition(ccp(480, 0)); CCMenuItemImage *bu06 = CCMenuItemImage::create("shangcheng.png", "shangcheng.png", this, menu_selector(HomeScene::menuItemCallBack)); bu06->setTag(6); bu06->setPosition(ccp(585, 0)); CCMenu* menu = CCMenu::create(bu01, bu02, bu03, bu04, bu05, bu06, NULL); menu->setPosition(ccp(0, 60)); menu->setAnchorPoint(ccp(0, 0.5)); this->addChild(menu); //系统公告 CCLabelTTF* sysLabel = CCLabelTTF::create("系统公告板:展示系统消息", "", 24.0f); sysLabel->setAnchorPoint( ccp(0, 0.5f) ); sysLabel->setPosition( ccp(size.width, size.height-25) ); this->addChild(sysLabel, 0, 100); // CCMoveBy* pMove = CCMoveBy::create(10.0f, ccp(-size.width-sysLabel->getContentSize().width, 0)); CCAction* pStop = CCCallFuncND::create(this, callfuncND_selector(HomeScene::actionDidFinished), NULL); sysLabel->runAction(CCSequence::create(pMove, pStop, NULL)); sysLabel->runAction(pMove); return true; }
bool WSGameScene::initWithGameCoreModeAndLevel(WSGameMode mode, uint16_t level) { if (CCScene::init()) { _gameCore = new WSGameCore; _gameCore->initWithGameModeAndMapName(mode, level, this); _backGroundLayer = new WSBackGroundLayer(); _backGroundLayer->init(); _backGroundLayer->setAnchorPoint(ccp(0, 0)); _backGroundLayer->setPosition(ccp(0, 0)); this->addChild(_backGroundLayer); _backGroundLayer->autorelease(); _gameBackGroundLayer = new WSGameBackGroundLayer(); _gameBackGroundLayer->initWithScene(this); _gameBackGroundLayer->setAnchorPoint(ccp(0, 0)); _gameBackGroundLayer->setPosition(ccp(0, 0)); this->addChild(_gameBackGroundLayer); _gameBackGroundLayer->autorelease(); _gameLayer = new WSGameLayer(); _gameLayer->initWithGameScene(this); _gameLayer->setAnchorPoint(ccp(0, 0)); _gameLayer->setPosition(ccp(0, 0)); this->addChild(_gameLayer); _gameLayer->autorelease(); _joyStick = new CCJoystick; _joyStick->setScale(3); _joyStick->init(10, 20, false, true, false, false); _joyStick->setAnchorPoint(ccp(0, 0)); _joyStick->setPosition(ccp(160, 350)); this->addChild(_joyStick); _joyStick->autorelease(); _joyStick->setBallTexture("joystick.png"); _joyStick->setDelegate(this); CCMenuItemImage* btn = CCMenuItemImage::create("btn.png", "btn.png", this, menu_selector(WSGameScene::btnClick)); btn->setPosition(ccp(980, 350)); btn->setScale(2.5); CCMenu* menu = CCMenu::createWithItem(btn); menu->setAnchorPoint(ccp(0, 0)); menu->setPosition(ccp(0, 0)); this->addChild(menu); this->startGame(); return true; } return false; }
void ADAds::fillBanner(Banner* banner) { #if defined(_DEBUG) && CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 CCRenderTexture* texture = CCRenderTexture::create(100, 100); texture->beginWithClear(0.5f, 0.5f, 0.5f, 1); texture->end(); CCSprite* s = CCSprite::createWithTexture(texture->getSprite()->getTexture()); s->setScaleX(banner->getContentSize().width/s->getContentSize().width); s->setScaleY(banner->getContentSize().height/s->getContentSize().width); banner->addChild(s); s->setAnchorPoint(ccp(0,0)); s->setPosition(ccp(0,0)); #endif if(_home_banners.size()) { //std::random_shuffle(_home_banners.begin(), _home_banners.end()); CustomBanner* home_ads = getCustomBanner(); CCMenuItem* item = CCMenuItem::create( home_ads, menu_selector(CustomBanner::onClick)); CCMenu* menu = CCMenu::create(); menu->addChild(item); banner->addChild(menu, 0, HOME_ADS_NODE_TAG); menu->setAnchorPoint(ccp(0,0)); menu->setPosition(ccp(0,0)); CCNode* banner_content = home_ads->getBanner(); CCSize content_size = banner_content->getContentSize(); CCSize zone_size = banner->getContentSize(); float scale = MIN(zone_size.width/content_size.width, zone_size.height/content_size.height); banner_content->setScale(scale); banner_content->setAnchorPoint(ccp(0, 0)); banner_content->setPosition(ccp(0,0)); item->setContentSize(content_size*scale); item->setAnchorPoint(ccp(0.5f,0.5f)); item->setPosition(zone_size*0.5f); item->addChild(banner_content); } }
bool CStartAndHelpButtonLayer::init() { if ( !CCLayer::init() ) { return false; } // get Windows Size //// start Button if ( CGameManager::GetInstance()->IsOnlineMode() && !CGameManager::GetInstance()->IsChannelMaster() ) { m_StartButton = CCMenuItemImage::create( GAME_SETTING_READY_BTN_UNSELECT.c_str(), GAME_SETTING_READY_BTN_SELECT.c_str(), this, menu_selector(CStartAndHelpButtonLayer::ReadyButtonCallBack) ); m_StartButton->setTag(READY_BUTTON_TAG); } else { m_StartButton = CCMenuItemImage::create( GAME_SETTING_READY_BTN_UNSELECT.c_str(), GAME_SETTING_READY_BTN_SELECT.c_str(), this, menu_selector(CStartAndHelpButtonLayer::StartButtonCallBack) ); m_StartButton->setTag(START_BUTTON_TAG); } // at init, Start button is disabled m_StartButton->setEnabled(false); m_StartButton->selected(); // create StartButtonMenu CCMenu *StartButtonMenu = CCMenu::create(m_StartButton, NULL); StartButtonMenu->setPosition(CCPoint(GAME_SETTING_READY_BTN_POS)); StartButtonMenu->setAnchorPoint(ccp(0, 0)); // add StartButtonMenu to Layer this->addChild(StartButtonMenu); // button Position & readyAnchorPoint (0, 0) m_StartButton->setPosition(ccp(0, 0)); m_StartButton->setAnchorPoint(ccp(0, 0)); return true; }
CCNode *createButtonToLayer(CCBalsamiqLayer *layer, BalsamiqControlData *controlData) { CCMenu *menu = CCMenu::create(); menu->setAnchorPoint(CCPointZero); menu->setPosition(CCPointZero); CCMenuItemImage *button = CCMenuItemImage::create("Icon-57.png", "Icon-57.png"); menu->addChild(button); button->setPosition(ccp(200, 100)); layer->addChild(menu); return button; }
bool RPGMapItemsMenuLayer::init(cocos2d::CCDictionary *stringList, CppSQLite3DB *db, float width, float height) { if(CCLayerColor::initWithColor(ccc4(0, 0, 0, 200), width, height)) { this->m_stringList = stringList; this->m_stringList->retain(); this->m_db = db; this->m_itemsList = new CCArray(); this->m_itemsList->init(); CCTMXTiledMap *mainBg = CCTMXTiledMap::create(CCString::createWithFormat("map_menu3_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString()); mainBg->setPosition(CCPointZero); mainBg->setTag(kRPGMapItemsMenuLayerTagBg); this->addChild(mainBg); CCMenu *mainMenu = CCMenu::create(); mainMenu->setTag(kRPGMapItemsMenuLayerTagMainMenu); mainMenu->setAnchorPoint(CCPointZero); mainMenu->setPosition(CCPointZero); this->addChild(mainMenu); CCMenuItemSprite *menuBack = (CCMenuItemSprite*)mainMenu->getChildByTag(kRPGMapItemsMenuLayerTagMainMenuBack); if(!menuBack) { menuBack = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapItemsMenuLayer::onMenu)); menuBack->setPosition(ccp(40, 600)); menuBack->setTag(kRPGMapItemsMenuLayerTagMainMenuBack); menuBack->setScale(0.5); mainMenu->addChild(menuBack); } CCTableView *tableView = CCTableView::create(this, CCSizeMake(900, 570)); tableView->setDirection(kCCScrollViewDirectionVertical); tableView->setPosition(ccp(80, 30)); tableView->setDelegate(this); tableView->setVerticalFillOrder(kCCTableViewFillTopDown); tableView->setTag(kRPGMapItemsMenuLayerTagItemListTable); this->addChild(tableView); this->loadItemsData(); return true; } return false; }
void GameWorld::CreateHUD() { // create & add score label char buf[8] = {0}; sprintf(buf, "Score:%d", score_); score_label_ = CCLabelBMFont::create(buf, "jcfont.fnt"); score_label_->setPosition(ccp(SCREEN_SIZE.width*0.5f, SCREEN_SIZE.height*0.925f)); addChild(score_label_, E_LAYER_HUD); // create & add the pause menu containing pause button CCMenuItemSprite* pause_button = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("cjbpause.png"), CCSprite::createWithSpriteFrameName("cjbpause.png"), this, menu_selector(GameWorld::OnPauseClicked)); pause_button->setPosition(ccp(SCREEN_SIZE.width*0.9f, SCREEN_SIZE.height*0.925f)); CCMenu* menu = CCMenu::create(pause_button, NULL); menu->setAnchorPoint(CCPointZero); menu->setPosition(CCPointZero); addChild(menu, E_LAYER_HUD); }
bool QuitScene::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } m_Sound = CCUserDefault::sharedUserDefault()->getBoolForKey("sound", true); CCPoint visibleOrigin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint visibleCenter = visibleOrigin + visibleSize / 2; CCSprite *sprite = CCSprite::create("bg1.jpg"); sprite->setPosition(visibleCenter); addChild(sprite); float yesX = visibleOrigin.x + visibleSize.width * 0.08f; CCMenuItemImage *pYes = LGMenuItemImage::create("quit_yes.png", NULL, this, menu_selector(QuitScene::yesCallback)); pYes->setPosition(ccp(yesX, visibleOrigin.y + visibleSize.height * 0.225f)); int adMRectLeft = NativeBridge::getAdMobMRectLeft(); CCMenuItemImage *pNo = LGMenuItemImage::create("quit_no.png", NULL, this, menu_selector(QuitScene::noCallback)); float noX = visibleOrigin.x + visibleSize.width * 0.31875f; noX = MIN(noX, visibleOrigin.x + adMRectLeft - 42); pNo->setPosition(ccp(noX, pYes->getPositionY())); sprite = CCSprite::create("quit_title.png"); sprite->setScale(0.72f); sprite->setPosition(ccp((yesX + noX) / 2, visibleOrigin.y + visibleSize.height * 0.7875f)); addChild(sprite); CCMenuItemImage *pMore = LGMenuItemImage::create("more.png", NULL, this, menu_selector(QuitScene::moreCallback)); pMore->setPosition(ccp(sprite->getPositionX(), visibleOrigin.y + visibleSize.height * 0.50625f)); CCMenu *pMenu = CCMenu::create(pYes, pNo, pMore, NULL); pMenu->setAnchorPoint(CCPointZero); pMenu->setPosition(CCPointZero); addChild(pMenu); return true; }
bool SGRankingLayer::init() { if(CCLayerColor::initWithColor(ccc4(255, 255, 255, 255))) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); SGSaveData* saveData = SGSaveData::sharedSaveData(); const unsigned long long *scroes = saveData->getHeroInfo().score; int padding = 20; int yPos = winSize.height/6; int xPos1 = winSize.width/2 - padding; int xPos2 = winSize.width - padding; for(int i=0; i<5; i++) { scoreLabel[i] = CCLabelAtlas::create(CCString::createWithFormat("%ld", scroes[i])->getCString(), "numbers.png", 20, 38, '0'); scoreLabel[i]->retain(); scoreLabel[i]->setAnchorPoint(ccp(1, 0.5)); scoreLabel[i]->setPosition(xPos1, winSize.height-yPos*(i+1)); this->addChild(scoreLabel[i], 1); } for(int i=5; i<10; i++) { scoreLabel[i] = CCLabelAtlas::create(CCString::createWithFormat("%ld", scroes[i])->getCString(), "numbers.png", 20, 38, '0'); scoreLabel[i]->retain(); scoreLabel[i]->setAnchorPoint(ccp(1, 0.5)); scoreLabel[i]->setPosition(xPos2, winSize.height-yPos*(i-5+1)); this->addChild(scoreLabel[i], 1); } CCMenuItemImage* exit_image = CCMenuItemImage::create("back.png","back_p.png",this,menu_selector(SGRankingLayer::back)); exit_image->setScale(0.5f); CCMenu* pexit = CCMenu::create(exit_image, NULL); pexit->setAnchorPoint(ccp(1,1)); pexit->setPosition(ccp(winSize.width-30,winSize.height-15)); this->addChild(pexit, 2); return true; } else { return false; } }
// on "init" you need to initialize your instance bool PPMainMenuLayer::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayerColor::initWithColor( ccc4(240, 235, 239, 255) ) ); ////////////////////////////////////////////////////////////////////////// CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); CCSize size = pEGLView->getVisibleSize(); CCLabelTTF* label = CCLabelTTF::create("JELLY", "Consolas", 40); label->setColor( ccc3(0, 0, 0) ); label->setAnchorPoint( ccp(0.5, 0.5) ); label->setPosition( ccp(size.width / 2, size.height * 2 / 3) ); addChild(label); PPCube* p = new PPCube( PPCube::PPCubeType_S ); p->setAnchorPoint( ccp(0.5, 0.5) ); p->setPosition( ccp( size.width / 2, (size.height * 2 / 3 - label->getContentSize().height) ) ); addChild(p); p->release(); label = CCLabelTTF::create("Play", "Consolas", 20); label->setColor( ccc3(0, 0, 0) ); CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(PPMainMenuLayer::MainMenuCallback)); CCMenu* pMenu =CCMenu::create(pMenuItem, NULL); pMenu->setAnchorPoint( ccp(0.5, 0.5) ); pMenu->setPosition( ccp(size.width / 2, size.height / 4) ); addChild(pMenu); bRet = true; } while (0); return bRet; }
//private void RPGDialogLayer::initCommons(string titleStr) { CCTMXTiledMap *mainBg = CCTMXTiledMap::create("alert_style1.tmx"); float x = (CCDirector::sharedDirector()->getWinSize().width - mainBg->getContentSize().width) / 2.0f; float y = (CCDirector::sharedDirector()->getWinSize().height - mainBg->getContentSize().height) / 2.0f; mainBg->setPosition(ccp(x, y)); mainBg->setTag(kRPGDialogLayerBg); this->addChild(mainBg); CCLabelTTF *titleLab = CCLabelTTF::create(titleStr.c_str(), "Arial", 25, CCSizeMake(mainBg->getContentSize().width, 25), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); titleLab->setPosition(ccp(190, 135)); titleLab->setColor(ccc3(255, 255, 255)); mainBg->addChild(titleLab); CCMenu *menu = CCMenu::create(); menu->setAnchorPoint(CCPointZero); menu->setPosition(CCPointZero); menu->setTag(kRPGDialogLayerBgMenu); mainBg->addChild(menu); }
void GameScene::showPauseView() { m_Paused = true; if (m_pPauseLayer == NULL) { m_pPauseLayer = LGLayerColor::create(ccc4(0, 0, 0, 0)); m_pPauseLayer->retain(); m_pPauseLayer->setTouchMode(kCCTouchesOneByOne); m_pPauseLayer->setTouchEnabled(true); m_pPauseLayer->setZOrder(3); CCSprite *pTitle = CCSprite::create("title_pause.png"); pTitle->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 2 , m_VisibleOrigin.y + m_VisibleSize.height * 0.67375f)); m_pPauseLayer->addChild(pTitle); CCMenuItemImage *pContinue = LGMenuItemImage::create("play.png", NULL, this, menu_selector(GameScene::continueCallback)); CCMenuItemImage *pMenu = LGMenuItemImage::create("menu.png", NULL, this, menu_selector(GameScene::menuCallback)); pContinue->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width * 0.26666667f, m_VisibleOrigin.y + m_VisibleSize.height * 0.41125)); pMenu->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width * 0.73333333f, pContinue->getPositionY())); CCMenu *pCCMenu = CCMenu::create(pContinue, pMenu, NULL); pCCMenu->setAnchorPoint(CCPointZero); pCCMenu->setPosition(CCPointZero); m_pPauseLayer->addChild(pCCMenu); } if (m_pPauseLayer && m_pPauseLayer->getParent() == NULL) { getParent()->addChild(m_pPauseLayer); CC_SAFE_RELEASE_NULL(m_CurrentLayer); m_CurrentLayer = m_pPauseLayer; m_CurrentLayer->retain(); onShowOverlay(true); } }
/* * 初始化 */ bool Demo::init() { // super init if (!CCLayer::init()) { return false; } CCMenuItemImage *pSellItem = CCMenuItemImage::create( "des.png", "des.png", this, menu_selector(Demo:: option)); pSellItem->setAnchorPoint(ccp(0, 0)); pSellItem->setPosition(ccp(0, 0)); CCMenu* menu = CCMenu::create(pSellItem, NULL); menu->setAnchorPoint(ccp(0, 0)); menu->setPosition(ccp(0, 0)); addChild(menu); CCSprite* sp = CCSprite::create("desfont.png"); sp->setAnchorPoint(ccp(0.5, 0)); sp->setPosition(ccp(320, 50)); addChild(sp); CCActionInterval * scale = CCScaleTo::create(1, 1.1); CCActionInterval * scale1 = CCScaleTo::create(1.5, 1); CCFiniteTimeAction * seq= CCSequence::create(scale, scale1, NULL); CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq); sp->runAction(repeatForever); /**/ LoginLayer* login = LoginLayer::create(); login->setVisible(false); login->setTouchEnabled(false); this->addChild(login, 1, 100); return true; }
void GameScene::showRateView() { if (m_pRateLayer == NULL) { m_pRateLayer = LGLayerColor::create(ccc4(0, 0, 0, 0)); m_pRateLayer->retain(); m_pRateLayer->setTouchMode(kCCTouchesOneByOne); m_pRateLayer->setTouchEnabled(true); m_pRateLayer->setZOrder(3); CCSprite *pBg = CCSprite::create("rate_bg.png"); pBg->setPosition(m_VisibleOrigin + m_VisibleSize / 2); m_pRateLayer->addChild(pBg); float bgW = pBg->getContentSize().width, bgH = pBg->getContentSize().height; CCMenuItemImage *pRate = LGMenuItemImage::create("rate_rate.png", NULL, this, menu_selector(GameScene::rateCallback)); pRate->setPosition(ccp(pBg->getPositionX() - 0.2592593f * bgW, pBg->getPositionY() - 0.6566f * bgH)); CCMenuItemImage *pLater = LGMenuItemImage::create("rate_later.png", NULL, this, menu_selector(GameScene::laterCallback)); pLater->setPosition(ccp(pBg->getPositionX() + 0.2592593f * bgW, pRate->getPositionY())); CCMenu *pMenu = CCMenu::create(pRate, pLater, NULL); pMenu->setAnchorPoint(CCPointZero); pMenu->setPosition(CCPointZero); m_pRateLayer->addChild(pMenu); } if (m_pRateLayer && m_pRateLayer->getParent() == NULL) { getParent()->addChild(m_pRateLayer); CC_SAFE_RELEASE_NULL(m_CurrentLayer); m_CurrentLayer = m_pRateLayer; m_CurrentLayer->retain(); onShowOverlay(true); } }
bool MainMenu::init() { if ( !CCLayer::init() ) { return false; } CCSprite* bg = CCSprite::create("TWtitle.png"); bg->setAnchorPoint(CCPointZero); addChild(bg); // create & add the play button's menu CCMenu* menu = CCMenu::create(); menu->setAnchorPoint(CCPointZero); menu->setPosition(CCPointZero); addChild(menu); // create & add the play button CCMenuItemSprite* play_button = CCMenuItemSprite::create(CCSprite::create("TWplaybtn.png"), CCSprite::create("TWplaybtn.png"), this, menu_selector(MainMenu::OnPlayClicked)); play_button->setPosition(ccp(SCREEN_SIZE.width * 0.5f, SCREEN_SIZE.height * 0.2f)); menu->addChild(play_button); return true; }
//private void RPGMapSceneLayer::startPlay(float delay) { CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap); //数据库部分,读取npc数据 CppSQLite3Query query = this->m_db.execQuery(CCString::createWithFormat(NPC_QUERY, this->m_mapData.mapId)->getCString()); while(!query.eof()) { float x = (stringToNumber<float>(query.getStringField("tmx_x")) + 0.5) * GAME_TMX_ROLE_WIDTH; float y = (stringToNumber<float>(query.getStringField("tmx_y")) + 0.5) * GAME_TMX_ROLE_HEIGHT; bool autoMove = query.getIntField("auto_move") == 1 ? true : false; RPGMapNPCRoleSprite *npc = RPGMapNPCRoleSprite::create(query.getIntField("id"), CCString::create(query.getStringField("map_texture")), CCString::create("head_texture"), CCString::create(query.getStringField("name_cns")), CCString::create(query.getStringField("content_cns")), 1, autoMove); npc->setTag(kRPGMapSceneLayerTagNPC + query.getIntField("id")); npc->setPosition(ccp(x, y)); bgMap->addChild(npc); query.nextRow(); } query.finalize(); //player int defaultSpriteFrameIndex = 1; //默认为向下 if(this->m_mapData.playerDirection.compare("up") == 0) { defaultSpriteFrameIndex = 10; } else if(this->m_mapData.playerDirection.compare("left") == 0) { defaultSpriteFrameIndex = 4; } else if(this->m_mapData.playerDirection.compare("right") == 0) { defaultSpriteFrameIndex = 7; } RPGMapRoleSprite *player = RPGMapRoleSprite::create(CCString::create("actor4_0.png"), CCString::create("Player"), true, defaultSpriteFrameIndex); player->setPosition(ccp(this->m_mapData.playerToX * GAME_TMX_ROLE_WIDTH, this->m_mapData.playerToY * GAME_TMX_ROLE_HEIGHT)); player->setTag(kRPGMapSceneLayerTagPlayer); player->m_type = kRPGMapRoleSpriteTypePlayer; bgMap->addChild(player); CCSprite *spJoystick = CCSprite::createWithSpriteFrameName("Ball.png"); CCSprite *joystickBg = CCSprite::createWithSpriteFrameName("Dock.png"); OzgJoystickLayer *joystick = OzgJoystickLayer::layerActivityJoystick(50, spJoystick, joystickBg, false); joystick->setTag(kRPGMapSceneLayerTagJoystick); joystick->m_target = this; joystick->m_endedSelector = callfunc_selector(RPGMapSceneLayer::joystickEndedFunc); this->addChild(joystick); //menu CCMenu *mainMenu = CCMenu::create(); mainMenu->setTag(kRPGMapSceneLayerTagMainMenu); mainMenu->setAnchorPoint(ccp(0.5, 0.5)); mainMenu->setPosition(CCPointZero); mainMenu->setContentSize(bgMap->getContentSize()); bgMap->addChild(mainMenu); CCMenuItemSprite *menuCommand = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapSceneLayer::onMenu)); menuCommand->setPosition(ccp(mainMenu->getContentSize().width - 35, mainMenu->getContentSize().height - 35)); menuCommand->setTag(kRPGMapSceneLayerTagMainMenuCommand); menuCommand->setRotation(180); menuCommand->setScale(0.75); mainMenu->addChild(menuCommand); // CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo(); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true); this->scheduleUpdate(); }
/** * 初始化方法,继承CCLayer的方法 */ bool LoginView::init() { if(!CCLayer::init()) { return false ; } CCSize winSize = CCDirector::sharedDirector()->getWinSize() ; // 背景 CCSprite* downBg = CCSprite::create("bg_welcome.png") ; downBg->setAnchorPoint(ccp(0.5, 0)) ; downBg->setPosition(ccp(winSize.width/2, 0)) ; this->addChild(downBg, 0) ; // 加载logo CCSprite* logo = CCSprite::create("logo_01.png") ; logo->setAnchorPoint(ccp(0.5, 0.5)) ; logo->setPosition(ccp(winSize.width/2, winSize.height/2+35)) ; this->addChild(logo, 1) ; ///////////////////////////////// 输入框 //////////////////////////////////////// const float input_width = 213.0f ; const float input_height = 39.0f ; const float labelNode_padding = 8.0f ; const float labelNode_width = winSize.width/3 ; const float labelNode_height = 2*input_height+labelNode_padding ; CCNode* labelNode = CCNode::create() ; labelNode->setContentSize(CCSizeMake(labelNode_width, labelNode_height)) ; labelNode->setAnchorPoint(ccp(0.5, 0)) ; labelNode->setPosition(ccp(winSize.width/2-5, 85)) ; this->addChild(labelNode, 2) ; CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create("bg_textfield.png") ; // 用户名 CCSprite* txtUsernameBg = CCSprite::createWithTexture(batchNode->getTexture()) ; txtUsernameBg->setAnchorPoint(ccp(0, 0)) ; txtUsernameBg->setPosition(ccp(0, input_height+labelNode_padding)) ; labelNode->addChild(txtUsernameBg, 0) ; this->txtUsername = CCTextFieldTTF::textFieldWithPlaceHolder("Username", CCSizeMake(input_width, input_height), kCCTextAlignmentLeft, "font01.ttf", 26.0f) ; this->txtUsername->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; this->txtUsername->setAnchorPoint(ccp(0, 0.5)) ; this->txtUsername->setPosition(ccp((winSize.width-labelNode_width)/2+5, 85+labelNode_height*3/4)) ; this->addChild(this->txtUsername, 3) ; // 密码 CCSprite* txtPasswordBg = CCSprite::createWithTexture(batchNode->getTexture()) ; txtPasswordBg->setAnchorPoint(ccp(0, 0)) ; txtPasswordBg->setPosition(ccp(0, 0)) ; labelNode->addChild(txtPasswordBg, 0) ; this->txtPassword = CCTextFieldTTF::textFieldWithPlaceHolder("Password", CCSizeMake(input_width, input_height), kCCTextAlignmentLeft, "font01.ttf", 26.0f) ; this->txtPassword->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; this->txtPassword->setAnchorPoint(ccp(0, 0.5)) ; this->txtPassword->setPosition(ccp((winSize.width-labelNode_width)/2+5, 85+labelNode_height/4-2)) ; this->addChild(this->txtPassword,3) ; // 登录按钮 CCMenuItemImage* loginMenuItem = CCMenuItemImage::create("menu_login_n.png", "menu_login_s.png", this, menu_selector(LoginView::menuLoginCallback)) ; loginMenuItem->setAnchorPoint(ccp(0, 0)) ; loginMenuItem->setPosition(ccp(0, input_height+labelNode_padding)) ; // 注册按钮 CCMenuItemImage* registeMenuItem = CCMenuItemImage::create("menu_registe_n.png", "menu_registe_s.png", this, menu_selector(LoginView::menuRegisteCallback)) ; registeMenuItem->setAnchorPoint(ccp(0, 0)) ; registeMenuItem->setPosition(ccp(0, 0)) ; CCMenu* loginMenu = CCMenu::create(loginMenuItem, registeMenuItem, NULL) ; loginMenu->setAnchorPoint(ccp(0, 0)) ; loginMenu->setPosition(ccp(input_width+10, -5)) ; labelNode->addChild(loginMenu) ; // ////////////////////////////////////////////////////////////////////////////////////////////// const float loginNode_padding = 11.0f ; const float loginNode_margin_bottom = 32.0f ; const float menu_item_width = 101.0f ; CCNode* optionNode = CCNode::create() ; optionNode->setContentSize(CCSizeMake(winSize.width/3, 50)) ; optionNode->setAnchorPoint(ccp(0.5, 0)) ; optionNode->setPosition(ccp(winSize.width/2-5, loginNode_margin_bottom)) ; this->addChild(optionNode, 1) ; // 游客登录 CCMenuItemImage* guestLoginItem = CCMenuItemImage::create("menu_guest_login_n.png", "menu_guest_login_s.png", this, menu_selector(LoginView::menuGuestLoginCallback)) ; guestLoginItem->setAnchorPoint(ccp(0, 0)) ; guestLoginItem->setPosition(ccp(0, 0)) ; // 忘记密码 CCMenuItemImage* forgetPwdItem = CCMenuItemImage::create("menu_forget_pwd_n.png", "menu_forget_pwd_s.png", this, menu_selector(LoginView::menuForgetPwdCallback)) ; forgetPwdItem->setAnchorPoint(ccp(0, 0)) ; forgetPwdItem->setPosition(ccp(menu_item_width+loginNode_padding, 0)) ; // go CCMenuItemImage* goMenuItem = CCMenuItemImage::create("menu_go_n.png", "menu_go_s.png", this, menu_selector(LoginView::menuGoCallback)) ; goMenuItem->setAnchorPoint(ccp(0, 0)) ; goMenuItem->setPosition(ccp(2*(menu_item_width+loginNode_padding), 0)) ; CCMenu* goMenu = CCMenu::create(guestLoginItem, forgetPwdItem, goMenuItem, NULL) ; goMenu->setAnchorPoint(ccp(0, 0)) ; goMenu->setPosition(ccp(0, 0)) ; optionNode->addChild(goMenu) ; /* ///////////////////////////////////////////////////////////////////////////////////////////// CCLabelTTF* tipLabel = CCLabelTTF::create("小提示:在游戏中达到规定时间,可以获取神秘大奖哦!", CCSizeMake(winSize.width, 45), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "font01.ttf", 22.0f) ; tipLabel->setAnchorPoint(ccp(0.5, 0)) ; tipLabel->setPosition(ccp(winSize.width/2, 20)) ; this->addChild(tipLabel, 2) ; */ // 接收键盘点击事件 this->setKeypadEnabled(true) ; // 触摸可使用 this->setTouchEnabled(true); return true ; }
bool MainMenu::init() { bool bRet = false; if(CCLayer::init()) { CCSize size = CCDirector::sharedDirector()->getWinSize(); hiScore = getHightScore(); crystals = getCrystals(); CCSprite* scoreBar = CCSprite::create("Menu/scoreBar.png"); scoreBar->setPosition(ccp(size.width,size.height)); scoreBar->setAnchorPoint(ccp(1,1)); this->addChild(scoreBar,10); CCSprite* logo = CCSprite::create("logo.png"); logo->setAnchorPoint(ccp(0,1)); logo->setPosition(ccp(0,size.height)); this->addChild(logo,5); CCString* hiScoreStr = CCString::createWithFormat("HIGHT SCORE : %d",hiScore); scoreT = CCLabelTTF::create(hiScoreStr->getCString(),"",20.0f); scoreT->setHorizontalAlignment(kCCTextAlignmentCenter); scoreT->setAnchorPoint(ccp(0.5,0.0)); scoreT->setColor(ccc3(0,255,255)); scoreT->setPosition(ccp(300,142)); scoreBar->addChild(scoreT); menusLayer = CCLayer::create(); this->addChild(menusLayer,1); mmL = CCLayer::create(); mmL->setPosition(0,0); mmL->setScale(0.5f); mmL->runAction( CCScaleTo::create(0.5f,1.0f) ); //moveMenuToNode(mmL); menusLayer->addChild(mmL,2); CCSprite* bgM = CCSprite::create("Menu/tabled.png"); bgM->setPosition(CCPointZero); bgM->setAnchorPoint(CCPointZero); mmL->addChild(bgM); omL = CCLayer::create(); omL->setPosition(-1024,0); omL->setScale(0.5); menusLayer->addChild(omL,2); CCSprite* bgO = CCSprite::create("Menu/tabled.png"); bgO->setPosition(CCPointZero); bgO->setAnchorPoint(CCPointZero); omL->addChild(bgO); gmL = CCLayer::create(); gmL->setPosition(1024,0); gmL->setScale(0.5); menusLayer->addChild(gmL,2); CCSprite* bgG = CCSprite::create("Menu/tabled.png"); bgG->setPosition(CCPointZero); bgG->setAnchorPoint(CCPointZero); gmL->addChild(bgG); CCMenuItemImage* ngB = CCMenuItemImage::create( "Menu/button_normal.png", "Menu/button_pushed.png", this, menu_selector(MainMenu::newGameClicked) ); CCLabelTTF* ngL = CCLabelTTF::create("NEW GAME","",40.0f); ngL->setPosition(ccp(200,110)); ngL->setAnchorPoint(ccp(0.5,0.5)); ngL->setHorizontalAlignment(kCCTextAlignmentCenter); //ngL->setColor(ccc3(119,207,7)); ngB->addChild(ngL); CCMenuItemImage* opB = CCMenuItemImage::create( "Menu/button_normal.png", "Menu/button_pushed.png", this, menu_selector(MainMenu::optionsClicked) ); CCLabelTTF* opL = CCLabelTTF::create("OPTIONS","",40.0f); opL->setPosition(ccp(200,110)); opL->setAnchorPoint(ccp(0.5,0.5)); opL->setHorizontalAlignment(kCCTextAlignmentCenter); //opL->setColor(ccc3(119,207,7)); opB->addChild(opL); CCMenuItemImage* exB = CCMenuItemImage::create( "Menu/button_normal.png", "Menu/button_pushed.png", this, menu_selector(MainMenu::exitClick) ); CCLabelTTF* exL = CCLabelTTF::create("EXIT","",40.0f); exL->setPosition(ccp(200,110)); exL->setAnchorPoint(ccp(0.5,0.5)); exL->setHorizontalAlignment(kCCTextAlignmentCenter); //exL->setColor(ccc3(119,207,7)); exB->addChild(exL); ngB->setPosition(size.width/2,350); opB->setPosition(size.width/2,220); exB->setPosition(size.width/2,90); CCMenu* mmM = CCMenu::create(ngB,opB,exB,NULL); mmM->setPosition(0,0); mmM->setAnchorPoint(CCPointZero); mmL->addChild(mmM); CCMenuItemImage* obackB = CCMenuItemImage::create( "Menu/back_normal.png", "Menu/back_pushedl.png", this, menu_selector(MainMenu::backClicked) ); bool isS = isSoundEnabled(); bool isM = isMusicEnabled(); bool isA = isAccelerometrControl(); CCMenuItemImage* oS = CCMenuItemImage::create( isS == true ? "Menu/tick_active.png" : "Menu/tick_deactive.png" , isS == true ? "Menu/tick_deactive.png" : "Menu/tick_active.png", this, menu_selector(MainMenu::optSetVolume) ); CCMenuItemImage* oM = CCMenuItemImage::create( isM == true ? "Menu/tick_active.png" : "Menu/tick_deactive.png" , isM == true ? "Menu/tick_deactive.png" : "Menu/tick_active.png", this, menu_selector(MainMenu::optSetMusic) ); CCMenuItemImage* oC = CCMenuItemImage::create( isA == true ? "Menu/tick_active.png" : "Menu/tick_deactive.png" , isA == true ? "Menu/tick_deactive.png" : "Menu/tick_active.png", this, menu_selector(MainMenu::optSetControls) ); /* CCSprite* line1 = CCSprite::create("Menu/line.png"); line1->setPosition(ccp(size.width/2,320)); line1->setAnchorPoint(ccp(0.5,0.5)); omL->addChild(line1);*/ CCLabelTTF* osL = CCLabelTTF::create("SOUND","",30.0f); osL->setAnchorPoint(ccp(0.5,0.5)); osL->setPosition(ccp(size.width/2 - 100,360)); osL->setColor(ccc3(255,196,0)); osL->setHorizontalAlignment(kCCTextAlignmentCenter); omL->addChild(osL); CCLabelTTF* omuL = CCLabelTTF::create("MUSIC","",30.0f); omuL->setAnchorPoint(ccp(0.5,0.5)); omuL->setPosition(ccp(size.width/2 - 100,230)); omuL->setColor(ccc3(255,196,0)); omuL->setHorizontalAlignment(kCCTextAlignmentCenter); omL->addChild(omuL); CCLabelTTF* ocL = CCLabelTTF::create("ACCELEROMETR","",30.0f); ocL->setAnchorPoint(ccp(0.5,0.5)); ocL->setPosition(ccp(size.width/2 - 100,100)); ocL->setColor(ccc3(255,196,0)); ocL->setHorizontalAlignment(kCCTextAlignmentCenter); omL->addChild(ocL); obackB->setPosition(850,150); oS->setPosition(size.width/2 + 100,370); oM->setPosition(size.width/2 + 100,240); oC->setPosition(size.width/2 + 100,110); CCMenu* opM = CCMenu::create(obackB,oS,oM,oC,NULL); opM->setAnchorPoint(CCPointZero); opM->setPosition(0,0); omL->addChild(opM); CCMenuItemImage* gbackB = CCMenuItemImage::create( "Menu/back_normal.png", "Menu/back_pushedl.png", this, menu_selector(MainMenu::backClicked) ); CCMenuItemImage* gPlay = CCMenuItemImage::create( "Menu/button_normal.png", "Menu/button_pushed.png", this, menu_selector(MainMenu::gameStartClicked) ); CCLabelTTF* plL = CCLabelTTF::create("PLAY","",40.0f); plL->setPosition(ccp(200,110)); plL->setAnchorPoint(ccp(0.5,0.5)); plL->setHorizontalAlignment(kCCTextAlignmentCenter); gPlay->addChild(plL); gbackB->setPosition(850,150); gPlay->setPosition(size.width/2,300); CCMenu* ngM = CCMenu::create(gbackB,gPlay,NULL); ngM->setPosition(0,0); ngM->setAnchorPoint(CCPointZero); gmL->addChild(ngM); stars1 = CCSprite::create("Backgrounds/stars.png"); stars2 = CCSprite::create("Backgrounds/stars.png"); fog = CCSprite::create("Backgrounds/fog.png"); garbage = CCSprite::create("Backgrounds/garbage.png"); planet = CCSprite::create("Backgrounds/planet.png"); bgSpace = CCParallaxNode::create(); bgSpace->addChild(stars1,-1,ccp(0.01f,0.01f),ccp(0,size.height/2)); bgSpace->addChild(stars2,-1,ccp(0.01f,0.01f),ccp(stars1->getContentSize().width,size.height/2)); bgSpace->addChild(fog,1,ccp(0.05f,0.05f),ccp(1000,size.height/2)); bgSpace->addChild(garbage,1,ccp(0.08f,0.08f),ccp(3000,size.height/2)); bgSpace->addChild(planet,0,ccp(0.03f,0.03f),ccp(600,size.height/2)); this->addChild(bgSpace,0); CCSprite* art = CCSprite::create("art.png"); art->setAnchorPoint(CCPointZero); art->setPosition(CCPointZero); this->addChild(art,15); art->runAction(CCSequence::create( CCDelayTime::create(3.0f),CCHide::create(), NULL )); this->scheduleUpdate(); bRet = true; } return bRet; }
bool SelectLevelScene::init(){ if(!CCScene::init()){ return false; } CCSprite* bg = CCSprite::create(Images::game::game_bg_jpg); addChild(bg, -1); bg->setAnchorPoint(ccp(0, 0)); CCMenu* menu = CCMenu::create(); addChild(menu, 1); menu->setAnchorPoint(ccp(0, 0)); menu->setPosition(ccp(0, 0)); CCMenuItem* backItem = UIUtil::getSingleImageBtn( Images::common::back); menu->addChild(backItem); backItem->setTarget(this, menu_selector(SelectLevelScene::onClickBtn)); backItem->setTag(-1); backItem->setAnchorPoint(ccp(1, 0)); LayoutUtil::layoutTo(backItem, 0, 1, bg, 0, 1, 4, -4); _stageImg = CCSprite::create(Images::selectLevel::level1); _stageClickedImg = CCSprite::create(Images::selectLevel::level1); _stageClickedImgMask = CCSprite::create(Images::selectLevel::level1); _stageClickedImgMask->setColor(ccBLACK); _stageClickedImgMask->setOpacity(80); _stageClickedImg->addChild(_stageClickedImgMask, 1); LayoutUtil::layoutToParentCenter(_stageClickedImgMask, _stageClickedImg); CCMenuItem* stageItem = CCMenuItemSprite::create(_stageImg, _stageClickedImg); stageItem->setTarget(this, menu_selector(SelectLevelScene::onClickBtn)); stageItem->setScale(1.3); stageItem->setTag(1); menu->addChild(stageItem); LayoutUtil::layoutToParentCenter(stageItem, this); CCMenuItem* leftArrow = UIUtil::getSingleImageBtn(Images::selectLevel::icon_arrow); leftArrow->setTarget(this, menu_selector(SelectLevelScene::prev)); menu->addChild(leftArrow); LayoutUtil::layoutTo(leftArrow, 1, 0.5, stageItem, 0, 0.5, -18); CCSprite* leftArrowBg = CCSprite::create(Images::selectLevel::icon_arrow); leftArrowBg->setScale(1.1); leftArrowBg->setColor(ccBLACK); addChild(leftArrowBg, 0); LayoutUtil::layoutToCenter(leftArrowBg, leftArrow); CCMenuItem* rightArrow = UIUtil::getSingleImageBtn(Images::selectLevel::icon_arrow); rightArrow->setTarget(this, menu_selector(SelectLevelScene::next)); menu->addChild(rightArrow); rightArrow->setScaleX(-1); LayoutUtil::layoutTo(rightArrow, 0, 0.5, stageItem, 1, 0.5, 18); CCSprite* rightArrowBg = CCSprite::create(Images::selectLevel::icon_arrow); rightArrowBg->setScaleX(-1.1); rightArrowBg->setScaleY(1.1); rightArrowBg->setColor(ccBLACK); addChild(rightArrowBg, 0); LayoutUtil::layoutToCenter(rightArrowBg, rightArrow); _stageIndexText = CCLabelTTF::create("01/11", "arial-bold", 30); _stageIndexText->setColor(ccBLACK); addChild(_stageIndexText, 1); LayoutUtil::layoutTo(_stageIndexText, 0.5, 0, stageItem, 0.5, 1, 0, -20); CCLabelTTF* title = CCLabelTTF::create("选择难度", "arial-bold", 38); title->setColor(ccBLACK); addChild(title, 1); LayoutUtil::layoutTo(title, 0.5, 0, _stageIndexText, 0.5, 1, 0, 20); MusicBtn* musicBtn = MusicBtn::create(); addChild(musicBtn, 1); LayoutUtil::layoutTo(musicBtn, 0, 0, bg, 0, 0, 5, 5); _curLevel = 0; AdUtil::showAd(); return true; }