LayerColor * LayerColor::create(const Color4B& color, GLfloat width, GLfloat height) { LayerColor * layer = new LayerColor(); if( layer && layer->initWithColor(color,width,height)) { layer->autorelease(); return layer; } CC_SAFE_DELETE(layer); return nullptr; }
bool GameOver::init() { ////////////////////////////// // 1. super init first if (!Scene::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// auto ac = Sprite::create(picOver); ac->setAnchorPoint(Vec2(0,0)); ac->setPosition(Vec2(0,0)); ac->setScaleX(visibleSize.width/ac->getTextureRect().getMaxX()); //设置精灵宽度缩放比例 ac->setScaleY(visibleSize.height/ac->getTextureRect().getMaxY()); this->addChild(ac,100); //半透明层 LayerColor* layerColor = CCLayerColor::create(); layerColor->setColor(cocos2d::Color3B(0, 0, 0)); layerColor->setOpacity(150); layerColor->setContentSize(Size(visibleSize.width, visibleSize.height)); this->addChild(layerColor,101); auto gameover = Sprite::create("setting/gameover.png"); //gameover->setAnchorPoint(Vec2(0,0)); gameover->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2)); this->addChild(gameover,102); scheduleUpdate(); return true; }
LayerColor * LayerColor::create(const Color4B& color) { LayerColor * layer = new (std::nothrow) LayerColor(); if(layer && layer->initWithColor(color)) { layer->autorelease(); return layer; } CC_SAFE_DELETE(layer); return nullptr; }
void SceneGame::addCtrlPanel() { Menu* menu = Menu::create(); this->addChild(menu); LayerColor* bg = LayerColor::create(Color4B(150, 80, 50, 255), winSize.width, winSize.height); addChild(bg, -1); bg->setGlobalZOrder(-300); MenuItemImage *regretItem = MenuItemImage::create("regret.jpg", "regret.jpg" , CC_CALLBACK_1(SceneGame::Regret,this)); menu->addChild(regretItem); moveNode(regretItem, Vec2(160, 60)); MenuItem* startServerItem = MenuItemFont::create("StartServer",CC_CALLBACK_1(SceneGame::startServer,this)); menu->addChild(startServerItem); moveNode(startServerItem, Vec2(160, 0)); MenuItem* startClientItem = MenuItemFont::create("StartClient",CC_CALLBACK_1(SceneGame::startClient,this)); menu->addChild(startClientItem); moveNode(startClientItem, Vec2(160, -60)); startServerItem->setUserObject(startClientItem); startClientItem->setUserObject(startServerItem); MenuItem* restartItem = MenuItemFont::create("Restart", CC_CALLBACK_1(SceneGame::Restart,this)); menu->addChild(restartItem); moveNode(restartItem, Vec2(160, -120)); if (_bRestart) { startServerItem->setEnabled(false); startClientItem->setEnabled(false); NetBattle::clear(); if (_bRedSide) { startServer(startServerItem); } else { startClient(startClientItem); } } }
LayerColor* LayerColor::create() { LayerColor* ret = new (std::nothrow) LayerColor(); if (ret && ret->init()) { ret->autorelease(); } else { CC_SAFE_DELETE(ret); } return ret; }
//游戏成功 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)); }
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; }
bool BuyChipLayer::init() { if(!PokerChildLayer::init()) { return false; } LayerColor *layer = LayerColor::create(Color4B(100,100,100,100)); this->addChild(layer); this->setTouchMode(Touch::DispatchMode::ONE_BY_ONE); this->setTouchEnabled(true); this->setSwallowsTouches(true); auto& size = Director::getInstance()->getWinSize(); auto layout = ui::Layout::create(); layout->setContentSize(size); layout->setTouchEnabled(true); layout->setAnchorPoint(Point::ZERO); this->addChild(layout, -10); auto root = CSLoader::createNode("LayerBuyChip1.csb"); this->addChild(root); Size winSize = Director::getInstance()->getWinSize(); LayerColor *layerBlack = LayerColor::create(Color4B(0, 0, 0, 100),winSize.width,winSize.height * 2); layerBlack->setPositionY(-winSize.height); this->addChild(layerBlack,-1); auto text_max_add = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_max_add")); auto text_min_add = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_min_add")); text_max_add->setString(tools::local_string("max_buy", "最多可添加")); text_min_add->setString(tools::local_string("min_buy", "最少可添加")); text_min_number_ = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_min_number")); text_max_number_ = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_max_number")); text_buy_number_ = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_buy_number")); auto btn_cancel = dynamic_cast<Button *>(CSLoader::seekNodeByName(root, "btn_cancel")); auto btn_confirm = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_confirm")); btn_cancel->addClickEventListener(std::bind(&BuyChipLayer::click_btn_cancel, this, std::placeholders::_1)); btn_confirm->addClickEventListener(std::bind(&BuyChipLayer::click_btn_confirm, this, std::placeholders::_1)); btn_cancel->setTitleText(tools::local_string("cancel","取消")); btn_confirm->setTitleText(tools::local_string("confirm_change_password","确定")); auto btn_add = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_add")); auto btn_sub = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_sub")); btn_add->addClickEventListener(std::bind(&BuyChipLayer::click_btn_add, this, std::placeholders::_1)); btn_sub->addClickEventListener(std::bind(&BuyChipLayer::click_btn_sub, this, std::placeholders::_1)); slider_chip_ = dynamic_cast<Slider*>(CSLoader::seekNodeByName(root, "slider_chip")); slider_chip_->addEventListener(std::bind(&BuyChipLayer::slider_slider_chip, this, std::placeholders::_1, std::placeholders::_2)); return true; }
// 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::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 GameWinLayer::init() { if (!Layer::init()) { return false; } Size visibleSize = Director::sharedDirector()->getVisibleSize(); // finish layer LayerColor* layerColor = LayerColor::create(); layerColor->setColor(Color3B(0, 0, 0)); layerColor->setOpacity(150); layerColor->setContentSize(Size(visibleSize.width, visibleSize.height)); this->addChild(layerColor, 1); return true; }
void Ajustes::initTitulo(){ LayerColor *capaPosTitulo = LayerColor::create(Color4B(23, 70, 108, 210), cuadroJuego->getContentSize().width-(espacioBordesCuadro*escala*2), 200*escala); capaPosTitulo->setAnchorPoint(Vec2(0,1)); capaPosTitulo->setPosition(anchoLateralCE+(espacioSuperiorBtAtras*escala),visibleSize.height-(200*escala)-(espacioSuperiorBtAtras*escala)); capaPosTitulo->setZOrder(1); this->addChild(capaPosTitulo); tituloEscena = CCLabelTTF::create(LanguageManager::getInstance()->getString("AjustesLbTitulo"), "HVD_Comic_Serif_Pro.ttf", 130*escala,CCSizeMake(anchoNoLateralCE, capaPosTitulo->getContentSize().height), TextHAlignment::CENTER); tituloEscena->setColor(Color3B(216,254,51)); tituloEscena->setVerticalAlignment(TextVAlignment::CENTER); tituloEscena->setAnchorPoint(Vec2(0, 0)); tituloEscena->setPosition(anchoLateralCE,capaPosTitulo->getPositionY()); tituloEscena->setZOrder(10); this->addChild(tituloEscena, 1); tituloEscena->retain(); }
void TTTBoard::addHorizontalGrids() { Color4B color = TTT_LINE_COLOR; int numLine = mGrid - 1; float lineThick = 6; float lineWidth = getContentSize().width; float y = (mGridSize - lineThick/2); Point pos = Point(0, y); for(int i=0; i<numLine; i++) { LayerColor *line = LayerColor::create(color, lineWidth, lineThick); line->setPosition(pos); addChild(line); pos.y += mGridSize; } }
void TTTBoard::addVerticalGrids() { Color4B color = TTT_LINE_COLOR; int numLine = mGrid - 1; float lineThick = 6; float lineHeight = getContentSize().height; float x = (mGridSize - lineThick/2); Point pos = Point(x, 0); for(int i=0; i<numLine; i++) { LayerColor *line = LayerColor::create(color, lineThick, lineHeight); line->setPosition(pos); addChild(line); pos.x += mGridSize; } }
// on "init" you need to initialize your instance bool Bug914Layer::init() { // always call "super" init // Apple recommends to re-assign "self" with the "super" return value if (BugsTestBaseLayer::init()) { auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(Bug914Layer::onTouchesBegan, this); listener->onTouchesMoved = CC_CALLBACK_2(Bug914Layer::onTouchesMoved, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); // ask director the the window size auto size = Director::getInstance()->getWinSize(); LayerColor *layer; for( int i=0;i < 5;i++) { layer = LayerColor::create(Color4B(i*20, i*20, i*20,255)); layer->setContentSize(Size(i*100, i*100)); layer->setPosition(Vec2(size.width/2, size.height/2)); layer->setAnchorPoint(Vec2(0.5f, 0.5f)); layer->ignoreAnchorPointForPosition(false); addChild(layer, -1-i); } // create and initialize a Label auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 64.0f); auto item1 = MenuItemFont::create("restart", CC_CALLBACK_1(Bug914Layer::restart, this)); auto menu = Menu::create(item1, nullptr); menu->alignItemsVertically(); menu->setPosition(Vec2(size.width/2, 100)); addChild(menu); // position the label on the center of the screen label->setPosition(Vec2( size.width /2 , size.height/2 )); // add the label as a child to this Layer addChild(label); return true; } return false; }
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; } }
void GameOverDialog::onEnter() { Node::onEnter(); Size visibleSize = Director::getInstance()->getVisibleSize(); // this->setContentSize(visibleSize); LayerColor *background = LayerColor::create(Color4B(0, 0, 0, 178)); this->addChild(background); // background->setContentSize(visibleSize); // TODO: We should decide winner in the game scene std::string filename = _playerLifePoint == _opponentLifePoint ? "labelDraw.png" : (_playerLifePoint > _opponentLifePoint ? "labelYouWin.png" : "labelYouLose.png"); Sprite *title = Sprite::create(filename); title->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); title->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.9f)); std::stringstream ss; ss << _playerLifePoint * 100 / INITIAL_PLAYER_LIFE << "% - " << _opponentLifePoint * 100 / INITIAL_PLAYER_LIFE << "%"; // TODO: Do not use magic number auto scoreLabel = ui::Text::create(ss.str(), FONT_DIGIT, 96); scoreLabel->setAnchorPoint(Vec2(0.5f, 0.5f)); scoreLabel->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.5f)); scoreLabel->setColor(Color3B::WHITE); _button = ui::Button::create(); _button->loadTextures("buttonOk.png", "buttonOkPressed.png"); _button->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); _button->setPosition(Vec2(visibleSize.width * 0.5f, visibleSize.height * 0.1f)); _button->addTouchEventListener(CC_CALLBACK_2(GameOverDialog::buttonPressed, this)); this->addChild(title); this->addChild(scoreLabel); this->addChild(_button); auto action = cocos2d::FadeTo::create(0.1, 178); background->setOpacity(0); background->runAction(action); }
// on "init" you need to initialize your instance bool MainLoadingScene::init() { if ( !Scene::init() ) { return false; } LayerColor *layer = LayerColor::create(); layer->initWithColor(Color4B(255, 255, 255, 255), VisibleRect::right().x , VisibleRect::top().y); layer->setPosition(VisibleRect::center()); layer->setAnchorPoint(Vec2(0.5f, 0.5f)); layer->setIgnoreAnchorPointForPosition(false); this->addChild(layer, 0); Sprite *fondo = Sprite::create("fondo.png"); fondo->setPosition(VisibleRect::center()); this->addChild(fondo); Sprite *sprite = Sprite::create("logo.png"); sprite->setPosition(VisibleRect::center()); this->addChild(sprite); Label *progress = Label::createWithTTF ("Kargatzen ari da.\nMesedez, minutu pare bat itxaron.", "fonts/PT_Sans-Web-Regular.ttf", 10); progress->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + 12)); progress->setAnchorPoint(Vec2(0.5,0.5)); progress->setColor(Color3B(0,0,0)); addChild(progress); loading = Sprite::create("loading.png"); loading->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + progress->getContentSize().height + loading->getContentSize().height / 2)); addChild(loading); ActionInterval* rotate = RotateBy::create(5.0f, 360.0f); RepeatForever *repeat = RepeatForever::create(rotate); loading->runAction(repeat); return true; }
// on "init" you need to initialize your instance bool Bug914Layer::init() { // always call "super" init // Apple recommends to re-assign "self" with the "super" return value if (BugsTestBaseLayer::init()) { setTouchEnabled(true); // ask director the the window size Size size = Director::getInstance()->getWinSize(); LayerColor *layer; for( int i=0;i < 5;i++) { layer = LayerColor::create(Color4B(i*20, i*20, i*20,255)); layer->setContentSize(Size(i*100, i*100)); layer->setPosition(Point(size.width/2, size.height/2)); layer->setAnchorPoint(Point(0.5f, 0.5f)); layer->ignoreAnchorPointForPosition(false); addChild(layer, -1-i); } // create and initialize a Label LabelTTF *label = LabelTTF::create("Hello World", "Marker Felt", 64); MenuItem *item1 = MenuItemFont::create("restart", CC_CALLBACK_1(Bug914Layer::restart, this)); Menu *menu = Menu::create(item1, NULL); menu->alignItemsVertically(); menu->setPosition(Point(size.width/2, 100)); addChild(menu); // position the label on the center of the screen label->setPosition(Point( size.width /2 , size.height/2 )); // add the label as a child to this Layer addChild(label); return true; } return false; }
bool WaitingNode::init() { if (!CustomNode::init()) { return false; } LayerColor* pBackground = LayerColor::create(ccc4(7, 25, 44, 150)); pBackground->setContentSize(CCSizeMake(640.0f, 960.0f)); this->addChild(pBackground); this->setContentSize(pBackground->getContentSize()); Sprite* pBackgroundBoard = Sprite::create("popup/panel_popup_waiting.png"); pBackgroundBoard->setPosition(Point(320.0f, 480.0f)); pBackgroundBoard->setScaleY(0.7f); this->addChild(pBackgroundBoard); m_pLabelTitle = LabelBMFont::create(m_sTitle, "fonts/font_title-popup.fnt", 410.0f, TextHAlignment::CENTER); m_pLabelTitle->setAnchorPoint(Point(0.5f, 0.5f)); m_pLabelTitle->setPosition(Point(320.0f, 485.0f)); this->addChild(m_pLabelTitle); return true; }
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; }
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 HWorld::winGame() { //添加胜利界面 auto size=Director::getInstance()->getWinSize(); LayerColor* layer = LayerColor::create(Color4B(0, 0, 0, 190), size.width, size.height); Sprite* sp = Sprite::create("win1.png"); 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(); }
bool SnakeLayer::init() { maximumLength = 100; itemsPicked = 0; score = 0; bonus = 0; direction = Point::ZERO; speed = 180; LayerColor* lc = LayerColor::create(Color4B(0, 0, 0, 210), PX(1.0f), PY(0.8f)); lc->setPosition(CP(0.5f, 0.5f)); lc->setAnchorPoint(Point(0.5f, 0.5f)); lc->ignoreAnchorPointForPosition(false); addChild(lc); bounds = lc->getBoundingBox(); LayerColor* scorebg = LayerColor::create(Color4B::BLACK, PX(1.0f), PY(0.1f)); scorebg->setPosition(Point::ZERO); addChild(scorebg); addChild(lineGroup = Node::create()); addChild(bonusGroup = Node::create()); addChild(itemGroup = Node::create()); LineNode* line = LineNode::create(CP(0.5f, 0.5f), CP(0.5f, 0.5f)); lineGroup->addChild(line); schedule(schedule_selector(SnakeLayer::considerSpawningBonus), 5.0f); scheduleUpdate(); lblScore = Label::createWithTTF(LS("ScoreColon") + " 0", NORMAL_TTF, 42.0f); lblScore->setColor(Color3B::WHITE); lblScore->setPosition(CP(0.5f, 0.05f)); //lblScore->enableGlow(Color4B::BLACK); //lblScore->enableShadow(Color4B::BLACK, Size::ZERO, 4); addChild(lblScore); string instruction = LS("SNAKE_INSTRUCTIONS"); lblInstruction = Label::createWithTTF(instruction, NORMAL_TTF, 48.0f); lblInstruction->setPosition(CP(0.5f, 0.5f)); lblInstruction->setHorizontalAlignment(TextHAlignment::CENTER); lblInstruction->setColor(Color3B::WHITE); lblInstruction->enableGlow(Color4B::RED); lblInstruction->runAction(RepeatForever::create( Sequence::createWithTwoActions(ScaleTo::create(1.0f, 1.1f), ScaleTo::create(1.0f, 1.0f)))); addChild(lblInstruction); instructionVisible = true; return true; }
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; }
bool EndGameNode::initLose() { if (!Node::init()) { return false; } LayerColor* pBackground = LayerColor::create(ccc4(7, 25, 44, 150)); pBackground->setContentSize(CCSizeMake(640.0f, 960.0f)); auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE); listener->setSwallowTouches(true); listener->onTouchBegan = [](Touch* touch, Event* event) { return true; }; EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, pBackground); this->addChild(pBackground); this->setContentSize(pBackground->getContentSize()); //m_pSpriteBatchNode = SpriteBatchNode::create("Target-End-Game/TargetEndgame.pvr.ccz"); //SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Target-End-Game/TargetEndgame.plist"); //this->addChild(m_pSpriteBatchNode); Sprite* pBackgroundBoard = Sprite::create("Target-End-Game/panel-level_popup.png"); pBackgroundBoard->setPosition(Point(320.0f, 610.0f)); this->addChild(pBackgroundBoard); Sprite* pLevelFailImage3 = Sprite::create("Target-End-Game/text_level_fail.png"); pLevelFailImage3->setPosition(Point(320.0f, 750.0f)); this->addChild(pLevelFailImage3); Sprite* pIconBoosterLock1 = Sprite::create("Target-End-Game/lock-icon-powerup.png"); pIconBoosterLock1->setPosition(Point(220.0f, 415.0f)); this->addChild(pIconBoosterLock1); Sprite* pIconBoosterLock2 = Sprite::create("Target-End-Game/lock-icon-powerup.png"); pIconBoosterLock2->setPosition(Point(320.0f, 415.0f)); this->addChild(pIconBoosterLock2); Sprite* pIconBoosterLock3 = Sprite::create("Target-End-Game/lock-icon-powerup.png"); pIconBoosterLock3->setPosition(Point(420.0f, 415.0f)); this->addChild(pIconBoosterLock3); FlashCardNode* pFlashCard = FlashCardNode::createLayout(m_mainWord); pFlashCard->setPosition(70.0f, 285.0f); pFlashCard->setScale(0.52f); this->addChild(pFlashCard); char sLevel[20]; int iCalLevel = GameConfigManager::getInstance()->CountLevelOfPreviousChapters(m_sChapterId); sprintf(sLevel, "Level %d", m_iCurrentLevel + iCalLevel); LabelBMFont *pLabelLevel = LabelBMFont::create(sLevel, "fonts/font-bechic.fnt"); pLabelLevel->setAnchorPoint(Point(0.5f, 0.5f)); pLabelLevel->setPosition(Point(320.0f, 870.0f)); this->addChild(pLabelLevel); LabelBMFont *pLabelScore = LabelBMFont::create("SCORE:", "fonts/font_score.fnt"); pLabelScore->setAnchorPoint(Point(0.5f, 0.5f)); pLabelScore->setPosition(Point(474.0f, 630.0f)); this->addChild(pLabelScore); LabelBMFont *pLabelNumScore = LabelBMFont::create(formatNumber(m_iScore).getCString(), "fonts/font_score.fnt"); pLabelNumScore->setAnchorPoint(Point(0.5f, 0.5f)); pLabelNumScore->setPosition(Point(474.0f, 585.0f)); pLabelNumScore->setScale(1.4f); this->addChild(pLabelNumScore); LeaderBoardtNode* pLeaderBoard = LeaderBoardtNode::createLayout(m_iCurrentLevel, m_sChapterId); pLeaderBoard->setPosition(Point(320.0f, 114.0f)); this->addChild(pLeaderBoard); Sprite* pButtonPlayGameSprite = Sprite::create("Target-End-Game/btn_replay.png"); ButtonNode* buttonPlayNode = ButtonNode::createButtonSprite(pButtonPlayGameSprite, CC_CALLBACK_1(EndGameNode::menuRetryLevelLoseCallBack, this)); buttonPlayNode->setPosition(Point(320.0f, 279.0f)); Sprite* pButtonCloseSprite = Sprite::create("Target-End-Game/btn_close.png"); ButtonNode* buttonCloseNode = ButtonNode::createButtonSprite(pButtonCloseSprite, CC_CALLBACK_1(EndGameNode::menuCloseLoseCallBack, this)); buttonCloseNode->setPosition(Point(572.0f, 894.0f)); ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create(); pButtonManagerNode->addButtonNode(buttonPlayNode); pButtonManagerNode->addButtonNode(buttonCloseNode); this->addChild(pButtonManagerNode); return true; }
bool EndGameNode::initWin() { if (!Node::init()) { return false; } LevelConfig* pLevelConfig = &GameConfigManager::getInstance()->GetLevelConfig(m_sChapterId, m_iCurrentLevel); m_iTotalBonusQuest = pLevelConfig->m_BonusQuestConfig.m_iBonusQuestCount; LayerColor* pBackground = LayerColor::create(ccc4(7, 25, 44, 150)); pBackground->setContentSize(CCSizeMake(640.0f, 960.0f)); auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE); listener->setSwallowTouches(true); listener->onTouchBegan = [](Touch* touch, Event* event) { return true; }; EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, pBackground); this->addChild(pBackground); this->setContentSize(pBackground->getContentSize()); //m_pSpriteBatchNode = SpriteBatchNode::create("Target-End-Game/TargetEndgame.pvr.ccz"); //SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Target-End-Game/TargetEndgame.plist"); //this->addChild(m_pSpriteBatchNode); Sprite* pBackgroundBoard = Sprite::create("Target-End-Game/panel-level_popup.png"); pBackgroundBoard->setPosition(Point(320.0f, 610.0f)); this->addChild(pBackgroundBoard); m_pStarAndBonusQuestNode = Node::create(); this->addChild(m_pStarAndBonusQuestNode); this->generateLayoutStartAndBonusQuest(); Sprite* pCompletedImage = Sprite::create("Target-End-Game/text_level_completed.png"); pCompletedImage->setPosition(Point(320.0f, 654.0f)); this->addChild(pCompletedImage); FlashCardNode* pFlashCard = FlashCardNode::createLayout(m_mainWord); pFlashCard->setPosition(70.0f, 200.0f); pFlashCard->setScale(0.52f); this->addChild(pFlashCard); char sLevel[20]; int iCalLevel = GameConfigManager::getInstance()->CountLevelOfPreviousChapters(m_sChapterId); sprintf(sLevel, "Level %d", m_iCurrentLevel + iCalLevel); LabelBMFont *pLabelLevel = LabelBMFont::create(sLevel, "fonts/font-bechic.fnt"); pLabelLevel->setAnchorPoint(Point(0.5f, 0.5f)); pLabelLevel->setPosition(Point(320.0f, 870.0f)); this->addChild(pLabelLevel); LabelBMFont *pLabelScore = LabelBMFont::create("SCORE:", "fonts/font_score.fnt"); pLabelScore->setAnchorPoint(Point(0.5f, 0.5f)); pLabelScore->setPosition(Point(474.0f, 525.0f)); this->addChild(pLabelScore); LabelBMFont *pLabelNumScore = LabelBMFont::create(formatNumber(m_iScore).getCString(), "fonts/font_score.fnt"); pLabelNumScore->setAnchorPoint(Point(0.5f, 0.5f)); pLabelNumScore->setPosition(Point(474.0f, 480.0f)); pLabelNumScore->setScale(1.4f); this->addChild(pLabelNumScore); Sprite* pButtonNextGameSprite = Sprite::create("Target-End-Game/btn_next.png"); ButtonNode* buttonNextNode = ButtonNode::createButtonSprite(pButtonNextGameSprite, CC_CALLBACK_1(EndGameNode::menuNextLevelCallBack, this)); buttonNextNode->setPosition(Point(425.0f, 279.0f)); Sprite* pButtonReplayGameSprite = Sprite::create("Target-End-Game/btn_replay.png"); ButtonNode* buttonReplayNode = ButtonNode::createButtonSprite(pButtonReplayGameSprite, CC_CALLBACK_1(EndGameNode::menuRetryLevelWinCallBack, this)); buttonReplayNode->setPosition(Point(225.0f, 279.0f)); Sprite* pButtonCloseSprite = Sprite::create("Target-End-Game/btn_close.png"); ButtonNode* buttonCloseNode = ButtonNode::createButtonSprite(pButtonCloseSprite, CC_CALLBACK_1(EndGameNode::menuCloseWinCallBack, this)); buttonCloseNode->setPosition(Point(572.0f, 894.0f)); ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create(); pButtonManagerNode->addButtonNode(buttonNextNode); pButtonManagerNode->addButtonNode(buttonCloseNode); pButtonManagerNode->addButtonNode(buttonReplayNode); this->addChild(pButtonManagerNode); m_levelInfo = LevelTable::getInstance()->getLevel(m_sChapterId, m_iCurrentLevel); m_chapterInfo = ChapterTable::getInstance()->getChapterInfo(m_sChapterId); if (m_levelInfo.bIsUnlock == false) { m_chapterInfo.iTotalLevelUnlock++; UserInfo userInfo = UserTable::getInstance()->getUserInfo(); userInfo.sCurrentChapterId = m_levelInfo.sChapterId; userInfo.iCurrentLevel = m_levelInfo.iLevel + 1; // Unlock chapter WordlMapConfig worldMapConfig = GameConfigManager::getInstance()->GetWordlMapConfig(); int iIndexCurrentChapter = worldMapConfig.m_WorlMapChapterConfigMap[m_levelInfo.sChapterId]; WordlMapConfig::WordMapChapterConfig worldMapChapterConfig = worldMapConfig.m_WorlMapChapterConfigs[iIndexCurrentChapter]; if (m_iCurrentLevel >= worldMapChapterConfig.m_iTotalevel) { //userInfo.iCurrentLevel = worldMapChapterConfig.m_iTotalevel; // Create data for new chapter std::string sNextChapterID; if ( GameConfigManager::getInstance()->GetNextChapterID(worldMapChapterConfig.m_sChapterId, sNextChapterID)) { InitDatabase::getInstance()->createDataChapterAndLevel(sNextChapterID); userInfo.sCurrentChapterId = sNextChapterID; userInfo.iCurrentLevel = 1; UserDefault::getInstance()->setStringForKey("ChapterPlayGame", userInfo.sCurrentChapterId); } else // the last chapter is finished so game is end now!!!! { } } UserTable::getInstance()->updateUser(userInfo); } m_levelInfo.bIsUnlock = true; m_levelInfo.iTotalBonusQuest = m_iTotalBonusQuest; if (m_levelInfo.iScore < m_iScore) { m_levelInfo.iScore = m_iScore; } if(m_levelInfo.iBonusQuest < m_iBonusQuestCompleted) { m_levelInfo.iBonusQuest = m_iBonusQuestCompleted; } if(m_levelInfo.iStar < m_iYellowStar) { m_chapterInfo.iTotalStar += m_iYellowStar - m_levelInfo.iStar; m_levelInfo.iStar = m_iYellowStar; } // Update Word for chapter const std::string sWordId = GameWordManager::getInstance()->GetWordIdFromWord(m_mainWord); WordInfo wordInfo = WordTable::getInstance()->getWordInfoOnChapter(m_levelInfo.sChapterId, sWordId); wordInfo.iCountCollected++; LevelTable::getInstance()->updateLevel(m_levelInfo); WordTable::getInstance()->updateWord(wordInfo); ChapterTable::getInstance()->updateChapter(m_chapterInfo); m_iCountYellowStar = 0; m_iCountBonusQuest = 0; this->sequenceUpdateStar(); LeaderBoardtNode* pLeaderBoard = LeaderBoardtNode::createLayout(m_iCurrentLevel, m_sChapterId); pLeaderBoard->setPosition(Point(320.0f, 114.0f)); this->addChild(pLeaderBoard); auto actionupdateDatabaseAndSync = CallFunc::create(this, callfunc_selector(EndGameNode::updateDatabaseAndSync)); this->runAction(Sequence::create(DelayTime::create(0.01f), actionupdateDatabaseAndSync, NULL)); 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); }
TableViewCell* Ranking::tableCellAtIndex(TableView *table, ssize_t idx) { RankingData *rankingData = _rankingData.at(idx); table->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN); TableViewCell *cell = table->dequeueCell(); if (!cell) { cell = new TableViewCell(); cell->autorelease(); } cell->removeAllChildren(); auto colorLayer = LayerColor::create(); colorLayer->setAnchorPoint(Point::ZERO); colorLayer->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width, TableViewItemHeightValue.asFloat())); colorLayer->setPosition(Vec2(0 * _tableViewRanking->getBoundingBox().size.width, 0)); cell->addChild(colorLayer); string numberRanking; ostringstream convert2; convert2 << idx + 1; numberRanking = convert2.str(); auto padding = 25; auto number = Label::createWithTTF(numberRanking, MainRegularFont, 60); number->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width / _totalLabels - padding, TableViewItemHeightValue.asFloat())); number->setWidth(_tableViewRanking->getBoundingBox().size.width / _totalLabels); number->setHeight(TableViewItemHeightValue.asFloat()); number->setVerticalAlignment(TextVAlignment::CENTER); number->setHorizontalAlignment(TextHAlignment::LEFT); number->setAnchorPoint(Point::ZERO); if (idx == 0) { number->setTextColor(IkasPurple); } else { number->setTextColor(IkasPurpleLight); } number->setPosition(Vec2(0 * _tableViewRanking->getBoundingBox().size.width + padding/ _totalLabels, 0)); cell->addChild(number); auto name = Label::createWithTTF(rankingData->getuser(), MainRegularFont, 60); name->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width / _totalLabels, TableViewItemHeightValue.asFloat())); name->setWidth(_tableViewRanking->getBoundingBox().size.width / _totalLabels); name->setHeight(TableViewItemHeightValue.asFloat()); name->setVerticalAlignment(TextVAlignment::CENTER); name->setHorizontalAlignment(TextHAlignment::CENTER); name->setAnchorPoint(Point::ZERO); if (idx == 0) { name->setTextColor(IkasPurple); } else { name->setTextColor(IkasPurpleLight); } name->setPosition(Vec2(0 * _tableViewRanking->getBoundingBox().size.width / _totalLabels, 0)); cell->addChild(name); string points; ostringstream convert; convert << rankingData->getpoints(); points = convert.str(); auto pointsLabel = Label::createWithTTF(points, MainRegularFont, 60); pointsLabel->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width / _totalLabels, TableViewItemHeightValue.asFloat())); pointsLabel->setHeight(TableViewItemHeightValue.asFloat()); pointsLabel->setWidth(_tableViewRanking->getBoundingBox().size.width / _totalLabels); pointsLabel->setVerticalAlignment(TextVAlignment::CENTER); pointsLabel->setHorizontalAlignment(TextHAlignment::CENTER); pointsLabel->setAnchorPoint(Point::ZERO); if (idx == 0) { pointsLabel->setTextColor(IkasPurple); } else { pointsLabel->setTextColor(IkasPurpleLight); } pointsLabel->setPosition(Vec2(1 * _tableViewRanking->getBoundingBox().size.width / _totalLabels, 0)); cell->addChild(pointsLabel); // // if (idx % 2 == 0) { // number->setTextColor(IkasWhite); // name->setTextColor(IkasWhite); // pointsLabel->setTextColor(IkasWhite); // colorLayer->setColor(Color3B(IkasRed)); // colorLayer->setOpacity(60); // } else { // number->setTextColor(IkasRed); // name->setTextColor(IkasRed); // pointsLabel->setTextColor(IkasRed); // colorLayer->setColor(Color3B(IkasWhite)); // colorLayer->setOpacity(0); // } LayerColor *topSeparator; if (idx % 2 == 0) { topSeparator = LayerColor::create(IkasPurpleLight); } else { topSeparator = LayerColor::create(IkasPurpleLightAlpha); } topSeparator->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width, 2)); topSeparator->setPosition(Vec2(0, TableViewItemHeightValue.asFloat() - 4)); topSeparator->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); cell->addChild(topSeparator); if (idx == _rankingData.size() - 1) { if (idx % 2 != 0) { topSeparator = LayerColor::create(IkasPurpleLight); } else { topSeparator = LayerColor::create(IkasPurpleLightAlpha); } topSeparator->setContentSize(Size(_tableViewRanking->getBoundingBox().size.width, 2)); topSeparator->setPosition(Vec2(0, 0)); topSeparator->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); cell->addChild(topSeparator); } return cell; }
bool Game1Scene::init(){ if (!LayerColor::initWithColor(GAME1_COLOR_APPCOLOR)) { return false; } else{ //初始化游戏UI auto gameUI = Game1UI::createLayer(); gameUI->setTag(999); this->addChild(gameUI); //初始化游戏背景 Size gameBoardSize = Size(GAME1_BLOCK_WIDTH * GAME1_COLS + GAME1_PADDING * (GAME1_COLS + 1), GAME1_BLOCK_HEIGHT * GAME1_ROWS + GAME1_PADDING * (GAME1_ROWS + 1)); gameBoard = LayerColor::create(GAME1_COLOR_BOARDCOLOR, gameBoardSize.width, gameBoardSize.height); Point gameBoardPoint = Point(70,(GAME1_WIN_SIZE_HEIGHT - gameBoardSize.height) / 2); gameBoard->setPosition(gameBoardPoint); this->addChild(gameBoard); //初始化Block for (int r = 0; r < GAME1_ROWS; r++) { for (int c = 0; c < GAME1_COLS; c++) { LayerColor * block = LayerColor::create(GAME1_COLOR_BLOCKCOLOR, GAME1_BLOCK_WIDTH, GAME1_BLOCK_HEIGHT); block->setPosition(c * (GAME1_BLOCK_WIDTH + GAME1_PADDING) + GAME1_PADDING, r * (GAME1_BLOCK_HEIGHT + GAME1_PADDING) + GAME1_PADDING); gameBoard->addChild(block); } } //初始化map for (int r = 0; r < GAME1_ROWS; r++) { for (int c = 0; c < GAME1_COLS; c++) { map[r][c] = -1; } } //初始化第一块Tile createOneTile(); //操作监控 auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [&](Touch * touch, Event * event){ //触摸开始时,记录下位置,作为后续触摸距离超过10像素的比较初始点 this->touchStartPoint = touch->getLocationInView(); log("touch began"); //设置标志位,表示新一轮开始,并且还没进行处理 this->touchIsEffective = false; return true; }; listener->onTouchMoved = [&](Touch * touch, Event * event){ //如果还没进行处理,才进行后续逻辑判断 if (!this->touchIsEffective) { //判断移动位置是否超过10像素,如果超过则证明当次移动已经有效,否则该移动无效 Vec2 touchCurrentPoint = touch->getLocationInView(); if (abs(touchCurrentPoint.x - this->touchStartPoint.x) >= GAME1_TOUCH_EFFECTIVE_DIS || abs(touchCurrentPoint.y - this->touchStartPoint.y) >= GAME1_TOUCH_EFFECTIVE_DIS) { this->touchIsEffective = true; log("touch is effect"); } //如果移动有效 if (this->touchIsEffective) { //判断移动的方向 if(touchCurrentPoint.x - this->touchStartPoint.x >= GAME1_TOUCH_EFFECTIVE_DIS){ this->currentDirection = RIGHT; //log("RIGHT"); } else if(this->touchStartPoint.x - touchCurrentPoint.x >= GAME1_TOUCH_EFFECTIVE_DIS){ this->currentDirection = LEFT; //log("LEFT"); } else if(touchCurrentPoint.y - this->touchStartPoint.y >= GAME1_TOUCH_EFFECTIVE_DIS){ this->currentDirection = DOWN; //log("DOWN"); } else if(this->touchStartPoint.y - touchCurrentPoint.y >= GAME1_TOUCH_EFFECTIVE_DIS){ this->currentDirection = UP; //log("UP"); } else{ this->currentDirection = NODIR; //log("NODIR"); //exit(1); } //进行一轮游戏逻辑的操作,该轮后续的滑动不再处理 this->oneRound(); } } }; Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); return true; } }