bool SkillTableView::init() { if (!Node::init()) return false; LayerColor* bg = LayerColor::create(Color4B(255, 255, 255, 127), 450, 500); bg->setPosition(bg->getContentSize()/-2); this->addChild(bg, -1); CCLabelTTF* title = CCLabelTTF::create("技能列表", "fonts/Marker Felt.ttf", 40); title->setPosition(Point(bg->getContentSize().width/2, bg->getContentSize().height-30)); bg->addChild(title); ControlButton* button = ControlButton::create(Scale9Sprite::create("ui/closed_normal.png")); button->setBackgroundSpriteForState(Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED); button->setPreferredSize(Size(57, 58)); button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()), button->getContentSize()/2)); this->addChild(button); button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE); // button->setTouchPriority(0); m_skillTableView = TableView::create(this, Size(420, 420)); m_skillTableView->setPosition(Point(15, 15)); // m_skillTableView->setDirection(kCCScrollViewDirectionVertical); m_skillTableView->setDelegate(this); // m_skillTableView->setVerticalFillOrder(kCCTableViewFillTopDown); bg->addChild(m_skillTableView); m_skillTableView->reloadData(); return true; }
Layer *TDDSuiteLayer::createStatusBarLayer() { Size screenSize = TDDHelper::getScreenSize(); int midY = kStatusBarHeight/2; int margin = 10; Point leftAnchor = Point(0, 0.5); Point rightAnchor = Point(1, 0.5); // Layer containter LayerColor *layer = LayerColor::create(kColorToolBar, screenSize.width, kStatusBarHeight); // Label *leftLabel = TDDHelper::createLabel("Left", kStatusBarFontSize, Color3B::WHITE); leftLabel->setAnchorPoint(leftAnchor); leftLabel->setPosition(Point(margin, midY)); layer->addChild(leftLabel); mStatusLeftLabel = leftLabel; Label *rightLabel = TDDHelper::createLabel("Right", kStatusBarFontSize, Color3B::WHITE); rightLabel->setAnchorPoint(rightAnchor); rightLabel->setPosition(Point(screenSize.width - margin, midY)); layer->addChild(rightLabel); // Setting Right Label char text[200]; sprintf(text, "%s %s (%d)", APP_NAME, VERSION, BUILD); rightLabel->setString(text); return layer; }
void Game2048::initUI() { //scene -> gameLayer -> root / uiNode LayerColor *gameLayer = LayerColor::create(Color4B(0xff, 0xff, 0xf0, 0xff)); this->addChild(gameLayer); Node *root = Node::create(); gameLayer->addChild(root); Node *uiNode = Node::create(); gameLayer->addChild(uiNode); lblScore = Label::createWithTTF("", "fonts/Marker Felt.ttf", 24); lblScore->setPosition(Vec2(DISPLAY_CX, DISPLAY_HEIGHT * 4 / 5)); uiNode->addChild(lblScore); //root -> bg bgSize = DISPLAY_WIDTH - offsetW; LayerColor *bgLayer = LayerColor::create(Color4B(0xcd, 0xba, 0x96, 0xff), bgSize, bgSize); bgLayer->setPosition(Point(DISPLAY_CX,DISPLAY_CY)); bgLayer->setAnchorPoint(Point(0.5, 0.5)); bgLayer->ignoreAnchorPointForPosition(false); root->addChild(bgLayer); //NumNode numSize = (bgSize - offsetW) / s_row ; for (int i = 0; i < s_row; i++) { for (int j = 0; j < s_row; j++) { int numberX = numSize*(i+0.5) + DISPLAY_CX - bgSize/2 + offsetW/2 ; int numberY = numSize*(j+0.5) + DISPLAY_CY - bgSize/2 + offsetW/2; Node *numNode = Node::create(); numNode->setPosition(Point(numberX, numberY)); root->addChild(numNode); //bg LayerColor *numBg = LayerColor::create(Color4B(200, 190, 180, 0xff), numSize-offsetW/2, numSize-offsetW/2); numBg->setAnchorPoint(Point(0.5, 0.5)); numBg->ignoreAnchorPointForPosition(false); numNode->addChild(numBg); //card cardNumbers[i][j] = 0; Node *cardNode = createNumCard(cardNumbers[i][j]); cardNodes[i][j] = cardNode; numNode->addChild(cardNode); } } randomCreateNum(); randomCreateNum(); }
void TDDSubMenu::setupHeader(const Color4B &headerColor) { GLfloat parentH = this->getContentSize().height; GLfloat width = this->getContentSize().width; GLfloat height = kHeaderHeight; LayerColor *headerLayer = LayerColor::create(headerColor, width, height); Point pos = Point(0, parentH - height); headerLayer->setPosition(pos); this->addChild(headerLayer); // Setting Buttons float scale = TDDHelper::getBestScale(); // Size screenSize = TDDHelper::getScreenSize(); int midY = height/2; int buttonW = (int)(scale * 50); int buttonH = height; int leftButtonX = buttonW / 2; int rightButtonX = width - leftButtonX; int midX = width/2; Size size = Size(buttonW, buttonH); ControlButton *button; pos.x = leftButtonX; pos.y = midY; button = createButton("back", kActionTagBack, pos, size); headerLayer->addChild(button); mBackButton = button; pos.x = rightButtonX; pos.y = midY; button = createButton("hide", kActionTagToggle, pos, size); headerLayer->addChild(button); button->addTargetWithActionForControlEvents(this, cccontrol_selector(TDDSubMenu::touchUpInsideAction), Control::EventType::TOUCH_UP_INSIDE); mToggleButton = button; // Label Label *title = Label::createWithSystemFont("MENU", "Arial", 15); title->setColor(Color3B::WHITE); title->setPosition(Point(midX, midY)); headerLayer->addChild(title); // mHeaderLayer = headerLayer; }
//游戏失败 void HWorld::lostGame() { //添加失败界面 auto size=Director::getInstance()->getWinSize(); const char* pic = ""; if(isGetNewRecord) { pic = "win1.png"; }else { pic = "lost1.png"; } LayerColor* layer = LayerColor::create(Color4B(0, 0, 0, 190), size.width, size.height); Sprite* sp = Sprite::create(pic); sp->setPosition(Vec2(size.width*0.5,size.height*0.5)); layer->addChild(sp); addChild(layer,100); //添加一个按钮用于返回Menu Label* ttback =Label::createWithSystemFont("返回主菜单", "Helvetica-Bold", 23); MenuItemLabel* menuLabel= MenuItemLabel::create(ttback, CC_CALLBACK_1(HWorld::backMenu, this)); menuLabel->setPosition(Vec2(0,-200)); Menu* menu =Menu::create(menuLabel,NULL); addChild(menu,100); //停止游戏 Director::getInstance()->pause(); SimpleAudioEngine::getInstance()->stopBackgroundMusic(); SimpleAudioEngine::getInstance()->stopAllEffects(); }
//游戏失败场景 void HWorld::lostGame() { Size size = Director::getInstance()->getWinSize(); //创建一个带有颜色的层 LayerColor *layer = LayerColor::create(Color4B(0, 0, 0, 190),size.width,size.height); //创建背景图片精灵 Sprite * sp = Sprite::create("game_lost.png"); sp->setPosition(Point(size.width/2, size.height/2)); layer->addChild(sp); this->addChild(layer,100); //设置菜单项字体 MenuItemFont::setFontName("Arial"); //设置菜单项字体大小 MenuItemFont::setFontSize(26); //创建一个只有字体的Menu按钮 MenuItemFont *item1 = MenuItemFont::create("返回主菜单", CC_CALLBACK_1(HWorld::backMenu, this)); //菜单选项卡在Menu中的坐标系是以屏幕的中点为原点 item1->setPosition(Point(0 , -200)); Menu * menu = Menu::create(item1,NULL); this->addChild(menu,100); //游戏暂停 Director::getInstance()->pause(); }
//TODO 屏蔽事件穿透 void BattleScene::createBottomBar() { LayerColor *bottom = LayerColor::create(Color4B(0, 0, 100, 100)); bottom->setContentSize(Size(WINSIZE.width, 120)); bottom->setPosition(Point(0, 0)); addChild(bottom); int totalCount = 11; int index = 0; Vector<MenuItem *> items; auto soldierInCamp = BattleData::getInstance()->getAttackSoldierInCamp(); map<int, vector<DSoldier *>>::iterator it; for(it=soldierInCamp.begin(); it!=soldierInCamp.end(); it++) { MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this)); item->setTag(it->first); items.pushBack(item); index++; //head Size size = item->getContentSize(); char img[20]; sprintf(img, "ui/%d.png", it->first / 100); auto head = Sprite::create(img); head->setAnchorPoint(Point(0.5, 0.5)); head->setPosition(size.width/2, size.height/2); item->addChild(head); char text[20]; sprintf(text, "X %d", it->second.size()); TTFConfig config("fonts/tahoma.ttf",16); auto count = Label::createWithTTF(config, text, TextHAlignment::LEFT); count->setPosition(size.width/2, size.height - count->getContentSize().height); item->addChild(count); //初始化为第一个兵种 if (m_selectedSoldierType <= 0) { m_selectedSoldierType = it->first; } } for (int i = index; i < totalCount; i++) { MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this)); item->setEnabled(false); items.pushBack(item); } Size bottomSize = bottom->getContentSize(); Sprite *spItem = Sprite::create("ui/618.0.png"); Size itemSize = spItem->getContentSize(); float padding = (bottomSize.width - itemSize.width * totalCount) / (totalCount + 1); UIRadioButton *radio = UIRadioButton::createWithArray(items); radio->alignItemsHorizontallyWithPadding(padding); radio->setPosition(Point(bottomSize.width / 2, bottomSize.height / 2)); radio->setSelectedIndex(0); bottom->addChild(radio); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. /**/ // add "HelloWorld" splash screen" auto sprite = Sprite::create("bkq.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer // this->addChild(sprite, 0); sprite->setTag(1024); //scheduleUpdate(); //schedule(schedule_selector(HelloWorld::updateTest), 1.0f, kRepeatForever,5.0f); /**/ //color4b rgbA LayerColorĬÈÏêµã0,0 LayerColor* redLayer = LayerColor::create(Color4B(255, 0, 0, 255), visibleSize.width / 2, visibleSize.height / 2); redLayer->ignoreAnchorPointForPosition(false); redLayer->setPosition(visibleSize / 2); redLayer->setAnchorPoint(Vec2(0.5, 0.5)); this->addChild(redLayer); LayerColor* blueLayer = LayerColor::create(Color4B(0, 0, 255, 255), visibleSize.width / 6, visibleSize.height / 6); blueLayer->ignoreAnchorPointForPosition(false); blueLayer->setAnchorPoint(Vec2(1, 1)); redLayer->addChild(blueLayer); /* DrawNode * rect = DrawNode::create(); addChild(rect); rect->setZOrder(10); rect->drawSolidRect(Vec2(100,100),Vec2(300,300),Color4F(1,0,0,1)); DrawNode * rect2 = DrawNode::create(); addChild(rect2); rect2->drawSolidRect(Vec2(150, 150), Vec2(350, 350), Color4F(0, 1, 0, 1)); DrawNode * rect3 = DrawNode::create(); addChild(rect3); rect3->drawSolidRect(Vec2(200, 200), Vec2(400, 400), Color4F(0, 0, 1, 1)); */ return true; }
//游戏成功 void Breakout::win() { unschedule(schedule_selector(Breakout::update)); unschedule(schedule_selector(Breakout::showTime)); LayerColor* gameOverLayer = LayerColor::create(Color4B(128, 128, 128, 128)); Label* over = Label::createWithSystemFont("You Win", "Arial", 80); over->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); gameOverLayer->addChild(over); this->addChild(gameOverLayer, 5); for (int i = 0; i < enemys.size(); i++) { enemys.at(i)->setVelocity(Vec2(0, 0)); } player->getPhysicsBody()->setVelocity(Vec2(0, 0)); }
Layer *TDDSuiteLayer::createToolBarLayer() { Size screenSize = TDDHelper::getScreenSize(); int midY = kToolBarHeight/2; int inputW = 140; int menuW = 70; int backX = 40; int findX = screenSize.width - menuW/2; int inputH = kToolBarHeight - 10; int inputX = findX - 10 - menuW / 2 - inputW / 2; LayerColor *menuLayer = LayerColor::create(kColorToolBar, screenSize.width, kToolBarHeight); Menu *menuBack = TDDHelper::createMenu(Point(backX, midY), "Back", CC_CALLBACK_1(TDDSuiteLayer::goBack, this)); menuLayer->addChild(menuBack); mEditFilter = TDDHelper::createEditBox(menuLayer, Point(inputX, midY), Size(inputW, inputH)); mEditFilter->setText(TDDHelper::getFilter()); mEditFilter->setDelegate(this); Menu *menuFind = TDDHelper::createMenu(Point(findX, midY), "Find", CC_CALLBACK_1(TDDSuiteLayer::filterTest, this)); menuLayer->addChild(menuFind); return menuLayer; }
//游戏失败 void Breakout::dead() { blood = 0; pT->setPercentage(blood); unschedule(schedule_selector(Breakout::update)); unschedule(schedule_selector(Breakout::showTime)); ParticleSystemQuad* fireWorks = ParticleSystemQuad::create("fire.plist"); fireWorks->setPosition(player->getPosition()); this->addChild(fireWorks); this->removeChild(player); LayerColor* gameOverLayer = LayerColor::create(Color4B(128, 128, 128, 128)); Label* over = Label::createWithSystemFont("Game Over", "Arial", 80); over->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2); gameOverLayer->addChild(over); this->addChild(gameOverLayer, 5); }
bool LoadingScene::init() { if (Layer::init()) { // add background to current scene LayerColor *bkGround = LayerColor::create(Color4B(0, 255, 255, 255)); this->addChild(bkGround); LabelTTF *logo = LabelTTF::create("tashaxing's 2048", "Arial", 30); logo->setColor(Color3B(255, 255, 0)); bkGround->addChild(logo); logo->setPosition(bkGround->getContentSize().width / 2, bkGround->getContentSize().height / 2); //添加音频预加载回调,注意,只有layer才能用schedule,scene不行 this->scheduleOnce(schedule_selector(LoadingScene::loadingCallBack), 0); return true; } else { return false; } }
bool CoverLayer::init() { if (!Layer::init()) { return false; } _fWidth = COMWinSize().width/2; _fHeight = 0.75*COMWinSize().width/2; LayerColor* layerBg = LayerColor::create(Color4B(104,177,59,255)); //LayerColor* layerBg = LayerColor::create(Color4B(146,220,121,255)); //LayerColor* layerBg = LayerColor::create(Color4B(130,207,191,255)); addChild(layerBg,0); Sprite* spBook = Sprite::create("image/cover_bookshelf.png"); spBook->setPosition(Point(COMWinSize().width/2,(COMWinSize().height-_fHeight*2)/2+_fHeight*2)); layerBg->addChild(spBook); _menuLayer = Layer::create(); _menuLayer->setVisible(false); addChild(_menuLayer); _LayerBtnStart = LayerColor::create(Color4B(101,233,232,255), _fWidth, _fHeight); _LayerBtnRecord = LayerColor::create(Color4B(70,187,242,255), _fWidth, _fHeight); _LayerBtnSet = LayerColor::create(Color4B(250,138,73,255), _fWidth, _fHeight); _LayerBtnComment = LayerColor::create(Color4B(159,213,111,255), _fWidth, _fHeight); _LayerBtnStart->setPosition(Point(0-_fWidth,_fHeight)); _menuLayer->addChild(_LayerBtnStart); _LayerBtnRecord->setPosition(Point(_fWidth+_fWidth,_fHeight)); _menuLayer->addChild(_LayerBtnRecord); _LayerBtnSet->setPosition(Point(0-_fWidth,0)); _menuLayer->addChild(_LayerBtnSet); _LayerBtnComment->setPosition(Point(_fWidth+_fWidth,0)); _menuLayer->addChild(_LayerBtnComment); return true; }
void TransitionCrossFade::onEnter() { TransitionScene::onEnter(); // create a transparent color layer // in which we are going to add our rendertextures Color4B color(0,0,0,0); Size size = _director->getWinSize(); LayerColor* layer = LayerColor::create(color); // create the first render texture for inScene RenderTexture* inTexture = RenderTexture::create((int)size.width, (int)size.height,Texture2D::PixelFormat::RGBA8888,GL_DEPTH24_STENCIL8); if (nullptr == inTexture) { return; } inTexture->getSprite()->setAnchorPoint( Vec2::ANCHOR_MIDDLE ); inTexture->setPosition(size.width/2, size.height/2); inTexture->setAnchorPoint( Vec2::ANCHOR_MIDDLE ); // render inScene to its texturebuffer inTexture->begin(); _inScene->visit(); inTexture->end(); // create the second render texture for outScene RenderTexture* outTexture = RenderTexture::create((int)size.width, (int)size.height,Texture2D::PixelFormat::RGBA8888,GL_DEPTH24_STENCIL8); outTexture->getSprite()->setAnchorPoint( Vec2::ANCHOR_MIDDLE ); outTexture->setPosition(size.width/2, size.height/2); outTexture->setAnchorPoint( Vec2::ANCHOR_MIDDLE ); // render outScene to its texturebuffer outTexture->begin(); _outScene->visit(); outTexture->end(); // create blend functions BlendFunc blend1 = {GL_ONE, GL_ONE}; // inScene will lay on background and will not be used with alpha BlendFunc blend2 = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; // we are going to blend outScene via alpha // set blendfunctions inTexture->getSprite()->setBlendFunc(blend1); outTexture->getSprite()->setBlendFunc(blend2); // add render textures to the layer layer->addChild(inTexture); layer->addChild(outTexture); // initial opacity: inTexture->getSprite()->setOpacity(255); outTexture->getSprite()->setOpacity(255); // create the blend action Action* layerAction = Sequence::create ( FadeTo::create(_duration, 0), CallFunc::create(CC_CALLBACK_0(TransitionScene::hideOutShowIn,this)), CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)), nullptr ); // run the blend action outTexture->getSprite()->runAction( layerAction ); // add the layer (which contains our two rendertextures) to the scene addChild(layer, 2, kSceneFade); }
// Tool bar constains the following elements // Back button // Filter Input // Switch // Layout: | BACK | INPUT .... SWITCH | // 800 or 480 // Landscape: | 80 // Portrait: | 80 | 80 | ... 120 | 400 - 120 = 280 - Layer *TDDSuiteLayer::createToolBarLayer() { float scale = TDDHelper::getBestScale(); // bool isLandscape = TDDHelper::isLandscape(); Size screenSize = TDDHelper::getScreenSize(); int midY = kToolBarHeight/2; int buttonW = (int)(scale * 90); int inputW = (int)(scale * 200); int switchW = (int)(scale * 130); int backX = buttonW/2; int inputH = kToolBarHeight - 10; int inputX = inputW / 2 + buttonW; int clearX = buttonW + buttonW/2; int switchY = 5; int switchX = screenSize.width - switchW - 10; int switchH = kToolBarHeight - switchY * 2; // Layer containter LayerColor *menuLayer = LayerColor::create(kColorToolBar, screenSize.width, kToolBarHeight); // Back Button Menu *menuBack = TDDHelper::createMenu(Point(backX, midY), "Back", CC_CALLBACK_1(TDDSuiteLayer::goBack, this)); menuLayer->addChild(menuBack); // Clear History button Menu *menuClear = TDDHelper::createMenu(Point(clearX, midY), "Clear", CC_CALLBACK_1(TDDSuiteLayer::clearHistory, this)); menuLayer->addChild(menuClear); mClearMenu = menuClear; mClearMenu->setVisible(false); // Filter Input mEditFilter = TDDHelper::createEditBox(menuLayer, Point(inputX, midY), Size(inputW, inputH)); mEditFilter->setText(TDDHelper::getFilter()); mEditFilter->setPlaceHolder("Testcase Filter"); mEditFilter->setDelegate(this); // Menu *menuFind = TDDHelper::createMenu(Point(findX, midY), "Find", // CC_CALLBACK_1(TDDSuiteLayer::filterTest, this)); // menuLayer->addChild(menuFind); // Switch TDDSwitch *switchControl = new TDDSwitch(Size(switchW, switchH), kColorSwitchBg, kColorSwitch, kColorSwitchOffText, kColorSwitchOnText, TDD_FONT_NAME, (int)(scale * TDD_FONT_SIZE2 )); switchControl->setPosition(Point(switchX, switchY)); menuLayer->addChild(switchControl); std::vector<std::string> switches; switches.push_back("all"); switches.push_back("history"); TDDMenuMode savedMode = TDDData::instance()->getMenuMode(); int index = 0; if(savedMode == TDDMenuModeHistory) { index = 1; } switchControl->setSwitches(switches, CC_CALLBACK_3(TDDSuiteLayer::switchSelected, this), index); return menuLayer; }
void Akuerdate::JuegoTerminado(){ CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("ganar.mp3"); escuchadores = false; juegoTerminado = true; LayerColor *lyConseguido = LayerColor::create(Color4B(124,180,224,200)); lyConseguido->setPosition(cuadroJuego->getPosition()); lyConseguido->setContentSize(cuadroJuego->getContentSize()); lyConseguido->setLocalZOrder(20); addChild(lyConseguido); Sprite *foco = Sprite::create("preguntator_focoLuz.png"); foco->setScaleX(escalaAlta); foco->setScaleY(0); foco->setScaleZ(escalaAlta); foco->setAnchorPoint(Vec2(0.5,1)); foco->setPosition(lyConseguido->getContentSize().width/2,lyConseguido->getContentSize().height); lyConseguido->addChild(foco); //animacion foco ScaleTo *aniFoco = ScaleTo::create(0.7, escalaAlta); foco->runAction(aniFoco); __String *txtConsegido = __String::createWithFormat("%s %s",LanguageManager::getInstance()->getString("JUEGO_TX_FINAL_EXITO_2").c_str(),sNombreProfesion->getCString()); CCLabelTTF *txConseguido = CCLabelTTF::create(txtConsegido->getCString(), "HVD_Comic_Serif_Pro.ttf",120*escala,Size((visibleSize.width),(220*escala)*2), TextHAlignment::CENTER); txConseguido->setColor(Color3B(25,78,121)); txConseguido->setVerticalAlignment(TextVAlignment::CENTER); txConseguido->setAnchorPoint(Vec2(0.5,1)); txConseguido->setPosition(lyConseguido->getContentSize().width/2,visibleSize.height+(280*escala)); lyConseguido->addChild(txConseguido); //animacion textoConsegido MoveTo *aniTxConseguido = MoveTo::create(0.3, Vec2(lyConseguido->getContentSize().width/2,(lyConseguido->getContentSize().height))); txConseguido->runAction(aniTxConseguido); Sprite *pizzarra = Sprite::create("pizzarra_final_tiempo.png"); pizzarra->setScale(escalaAlta); pizzarra->setAnchorPoint(Vec2(0.5,1)); pizzarra->setPosition(visibleSize.width,(lyConseguido->getContentSize().height)-(txConseguido->getContentSize().height)); lyConseguido->addChild(pizzarra); CCLabelTTF *nAciertosPizarra = CCLabelTTF::create(reloj->getString(), "HVD_Comic_Serif_Pro.ttf",200,pizzarra->getContentSize(), TextHAlignment::CENTER); nAciertosPizarra->setColor(Color3B(255,255,255)); nAciertosPizarra->setVerticalAlignment(TextVAlignment::CENTER); nAciertosPizarra->setAnchorPoint(Vec2(0,0)); nAciertosPizarra->setPosition(0,0); pizzarra->addChild(nAciertosPizarra); //animacion pizzara MoveTo *aniPizzarra = MoveTo::create(0.3, Vec2(lyConseguido->getContentSize().width/2,pizzarra->getPositionY())); pizzarra->runAction(aniPizzarra); CGestorRecursos *gRecursos = new CGestorRecursos(); CRecurso *recursoAleatorio = gRecursos->obtenerRecursoBloqueadoAleatorio(); if(recursoAleatorio!=NULL){ gRecursos->quitarRecursoBloqueado(recursoAleatorio); Sprite *txPremio = Sprite::create("preguntator_finjuego_texto_inferior.png"); txPremio->setScale(escalaAlta); txPremio->setAnchorPoint(Vec2(0.5,0)); txPremio->setPosition(foco->getPositionX(),foco->getPositionY()-(foco->getContentSize().height*escalaAlta)); txPremio->setOpacity(0); lyConseguido->addChild(txPremio); //animacion txPremio Sequence *aniPremio1 = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); txPremio->runAction(aniPremio1); Sprite *premio = Sprite::create(recursoAleatorio->uri->getCString()); float escalaPremio = ((pizzarra->getContentSize().height*pizzarra->getScale())/2)/premio->getContentSize().height; float escalaPremioAncha = ((pizzarra->getContentSize().width*pizzarra->getScale()))/premio->getContentSize().width; if(escalaPremioAncha<escalaPremio) escalaPremio = escalaPremioAncha; premio->setScale(escalaPremio); premio->setAnchorPoint(Vec2(0.5,0)); premio->setPosition(txPremio->getPositionX(),txPremio->getPositionY()+(20*escalaPremio)+(txPremio->getContentSize().height*txPremio->getScaleY())); premio->setOpacity(0); //nuevo if(recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoOjos&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoAccesorio&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoDientes&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoColor) premio->runAction(TintTo::create(0,0,0,0)); lyConseguido->addChild(premio); string textoTraducido1 = LanguageManager::getInstance()->getString("kitDe"); string keyTexto2 = __String::createWithFormat("tipoRecurso%i",recursoAleatorio->tipoRecurso->getValue())->getCString(); string textoTraducido2 = LanguageManager::getInstance()->getString(keyTexto2); string textoFinal = __String::createWithFormat("%s %s",textoTraducido1.c_str(),textoTraducido2.c_str())->getCString(); CCLabelTTF *nAciertosPizarra = CCLabelTTF::create(textoFinal, "HVD_Comic_Serif_Pro.ttf",60,Size(lyConseguido->getContentSize().width,txPremio->getContentSize().height), TextHAlignment::CENTER); nAciertosPizarra->setColor(Color3B(229,57,57)); nAciertosPizarra->setVerticalAlignment(TextVAlignment::BOTTOM); nAciertosPizarra->setAnchorPoint(Vec2(0.5,0)); nAciertosPizarra->setPosition(txPremio->getContentSize().width/2,80); nAciertosPizarra->setOpacity(0); txPremio->addChild(nAciertosPizarra); Sequence *aniNAciertosPizarra = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); nAciertosPizarra->runAction(aniNAciertosPizarra); //nuevo Sequence *aniPremio = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); premio->runAction(aniPremio); //efecto flotando RotateTo *rotarIzq = RotateTo::create(1, 10); RotateTo *rotarDer = RotateTo::create(1, -10); Sequence *total1 = Sequence::create(rotarIzq,rotarDer, NULL); Sequence *total2 = Sequence::create(rotarDer->clone(),rotarIzq->clone(), NULL); RepeatForever *repeticion1 = RepeatForever::create(total1); RepeatForever *repeticion2 = RepeatForever::create(total2); premio->runAction(repeticion1); } }
bool CLoginLayer::init() { CBaseLayer::initWithColor(Color4B(26,11,24, 255)); m_pListener = EventListenerTouchOneByOne::create(); m_pListener->setSwallowTouches(true); m_pListener->onTouchBegan = CC_CALLBACK_2(CLoginLayer::onTouchBegan, this); m_pListener->onTouchMoved = CC_CALLBACK_2(CLoginLayer::onTouchMoved, this); m_pListener->onTouchEnded = CC_CALLBACK_2(CLoginLayer::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(m_pListener,this); m_pBig = Sprite::create("login/login_d1.png"); m_pBig->setPosition(m_winSize.width*0.5,m_winSize.height*0.5); addChild(m_pBig); m_pBig2 = Sprite::create("login/login_d2.png"); m_pBig2->setOpacity(0); m_pBig2->setPosition(m_winSize.width*0.5,m_winSize.height*0.5); addChild(m_pBig2); m_pBig3 = Sprite::create("login/login_d3.png"); m_pBig3->setOpacity(0); m_pBig3->setPosition(m_winSize.width*0.5,m_winSize.height*0.5); addChild(m_pBig3); Size tBg = m_pBig->getBoundingBox().size; m_lBeginTime = 0; m_pBig->runAction(Sequence::create(DelayTime::create(2.5),FadeOut::create(0.5),CallFunc::create([=](){ m_iChangeState = 1; }), NULL)); m_pBig2->runAction(Sequence::create(DelayTime::create(3.5),FadeIn::create(1),DelayTime::create(2.5),FadeOut::create(0.5),CallFunc::create([=](){ m_iChangeState = 2; }),NULL)); m_pBig3->runAction(Sequence::create(DelayTime::create(8),FadeIn::create(1),NULL)); //1024X196 LayerColor *pLayer = LayerColor::create(Color4B(0,0,0,255*0.6),m_winSize.width,196); pLayer->setPosition(0,-m_winSize.height*0.025); addChild(pLayer,1); m_strText = "那是一个众神消逝的时代,那是一片危机四伏的大陆。很难想象,如果没有他,相比其他种族而言如此弱小的人类,到底会如何惨淡的结束。是时代造就了英雄,还是英雄造就了时代?\n"; m_sAuthor = "出自《唯一魔导召唤师的一生》 王国卫队长卡尔 著"; Size tbg = pLayer->getBoundingBox().size; m_pTextInfo = Label::createWithTTF(m_strText.substr(0,1),"fonts/cuti.ttf",30,Size(tbg.width*0.9,0)); m_pTextInfo->setAnchorPoint(Vec2(0.5,1)); m_pTextInfo->setColor(Color3B(205,196,161)); m_pTextInfo->setPosition(tbg.width*0.5,tbg.height*0.85); pLayer->addChild(m_pTextInfo); //,Size(tbg.width*0.9,0) m_pTextAuthor = Label::createWithTTF(m_sAuthor,"fonts/cuti.ttf",25); m_pTextAuthor->setColor(Color3B(205,196,161)); m_pTextAuthor->setAnchorPoint(Vec2(0.5,1)); //-tbg.width*0.05 m_pTextAuthor->setPosition(m_winSize.width-m_pTextAuthor->getContentSize().width*0.5-tbg.width*0.05,m_winSize.height*0.05); m_pTextAuthor->setVisible(false); addChild(m_pTextAuthor,10); scheduleUpdate(); return true; }
void FriendListScene::buildScene() { _friendDictionary.clear(); _friendList.clear(); _tableView = NULL; _downloadCount = 0; const char* headerString = ""; switch (_selectedFriendCircle) { case ALL_FRIENDS: headerString = "All Friends"; break; case INSTALLED_ONLY: headerString = "Friends Playing Game"; break; case NON_PLAYING_ONLY: headerString = "Friends not Playing Game"; break; case MY_DEVICE_ONLY: #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) headerString = "Friends playing on iOS Device"; #else headerString = "Friends playing on Android Device"; #endif default: break; } //_friendList = CCArray::createWithCapacity(5); //_friendList->retain(); CCLOG("ALL Request count = %lu", _friendList.size()); // Add background layers to the scene. LayerColor *bg = LayerColor::create(Color4B(255, 255, 255, 255), AppDelegate::SCREEN_WIDTH, AppDelegate::SCREEN_HEIGHT); this->addChild(bg); LayerColor *secondBG = LayerColor::create(Color4B(95, 95, 95, 255), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), AppDelegate::SCREEN_HEIGHT - SCALED_VALUE(20.0f)); secondBG->setPosition(Point(SCALED_VALUE(10.0f), SCALED_VALUE(10.0f))); this->addChild(secondBG); // Set the table header. LayerColor *header = LayerColor::create(Color4B(66, 66, 66, 255), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), SCALED_VALUE(100.0f)); header->setAnchorPoint(Point(0, 0)); header->setPosition(Point(SCALED_VALUE(10.0f), AppDelegate::SCREEN_HEIGHT - SCALED_VALUE(110.0f))); this->addChild(header); // Set the header text. auto headerText = LabelTTF::create(headerString, "Arial", SCALED_VALUE(40.0f)); headerText->setAnchorPoint(Point(0.0f, 0.5f)); header->addChild(headerText); headerText->setPositionX(SCALED_VALUE(28.0f)); headerText->setPositionY(header->getContentSize().height/2); // Add back button go back to previous scene MenuItemImage *backButton = MenuItemImage::create(); backButton->setNormalSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_table_back_nrl")); backButton->setSelectedSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_table_back_prd")); backButton->setCallback(CC_CALLBACK_1(FriendListScene::backButtonPressed, this)); backButton->setAnchorPoint(Point(1.0f, 0.5)); Menu* backMenu = Menu::create(backButton, NULL); header->addChild(backMenu); backMenu->setPositionX(header->getContentSize().width - SCALED_VALUE(20.0f)); backMenu->setPositionY(header->getContentSize().height/2); // Create the table view. float tableHeight = bg->getContentSize().height - secondBG->getPositionY() - (header->getContentSize().height) - SCALED_VALUE(10); _tableView = TableView::create(this, Size(secondBG->getContentSize().width, tableHeight)); _tableView->setAnchorPoint(Point(0, 0.0)); _tableView->setDirection(ScrollView::Direction::VERTICAL); _tableView->setPosition(Point(SCALED_VALUE(10.0f), SCALED_VALUE(10))); _tableView->setDelegate(this); this->addChild(_tableView); }