Sprite3DWithOBBPerfromanceTest::Sprite3DWithOBBPerfromanceTest() { auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesBegan, this); listener->onTouchesEnded = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesEnded, this); listener->onTouchesMoved = CC_CALLBACK_2(Sprite3DWithOBBPerfromanceTest::onTouchesMoved, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); auto s = Director::getInstance()->getWinSize(); initDrawBox(); addNewSpriteWithCoords(Vec2(s.width/2, s.height/2)); MenuItemFont::setFontName("fonts/arial.ttf"); MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(Sprite3DWithOBBPerfromanceTest::delOBBCallback, this)); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(Sprite3DWithOBBPerfromanceTest::addOBBCallback, this)); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, nullptr); menu->alignItemsHorizontally(); menu->setPosition(Vec2(s.width/2, s.height-65)); addChild(menu, 1); TTFConfig ttfCount("fonts/Marker Felt.ttf", 30); _labelCubeCount = Label::createWithTTF(ttfCount,"0 cubes"); _labelCubeCount->setColor(Color3B(0,200,20)); _labelCubeCount->setPosition(Vec2(s.width/2, s.height-90)); addChild(_labelCubeCount); _hasCollider = false; addOBBCallback(nullptr); scheduleUpdate(); }
EffectSpriteTest::EffectSpriteTest() { if (ShaderTestDemo2::init()) { auto s = Director::getInstance()->getWinSize(); auto itemPrev = MenuItemImage::create("Images/b1.png", "Images/b2.png", [&](Ref *sender) { _vectorIndex--; if(_vectorIndex<0) _vectorIndex = _effects.size()-1; _sprite->setEffect(_effects.at(_vectorIndex)); }); auto itemNext = MenuItemImage::create("Images/f1.png", "Images/f2.png", [&](Ref *sender) { _vectorIndex++; if(_vectorIndex>=_effects.size()) _vectorIndex = 0; _sprite->setEffect(_effects.at(_vectorIndex)); }); auto menu = Menu::create(itemPrev, itemNext, NULL); menu->alignItemsHorizontally(); menu->setScale(0.5); menu->setAnchorPoint(Vec2(0,0)); menu->setPosition(Vec2(s.width/2,70)); addChild(menu); _sprite = EffectSprite::create("Images/grossini.png"); _sprite->setPosition(Vec2(0, s.height/2)); addChild(_sprite); auto jump = JumpBy::create(4, Vec2(s.width,0), 100, 4); auto rot = RotateBy::create(4, 720); auto spawn = Spawn::create(jump, rot, NULL); auto rev = spawn->reverse(); auto seq = Sequence::create(spawn, rev, NULL); auto repeat = RepeatForever::create(seq); _sprite->runAction(repeat); // set the Effects _effects.pushBack(EffectBlur::create()); _effects.pushBack(EffectOutline::create()); _effects.pushBack(EffectNoise::create()); _effects.pushBack(EffectEdgeDetect::create()); _effects.pushBack(EffectGreyScale::create()); _effects.pushBack(EffectSepia::create()); _effects.pushBack(EffectBloom::create()); _effects.pushBack(EffectCelShading::create()); _effects.pushBack(EffectLensFlare::create()); _vectorIndex = 0; _sprite->setEffect( _effects.at(_vectorIndex) ); // _sprite->addEffect( _effects.at(8), -10 ); // _sprite->addEffect( _effects.at(1), 1 ); } }
void HeroInformationMenuLayer::addMenu(){ menuBG = Sprite::create("HeroChangeWindow.png"); menuBG->setPosition(vSize / 2); //图片缩放比例 float flexibleX = vSize.width / 2 / menuBG->getContentSize().width; float flexibleY = vSize.height / menuBG->getContentSize().height; menuBG->setScale(flexibleX, flexibleY); this->addChild(menuBG, 1); log("%f %f", flexibleY, flexibleX); //退出按钮 auto returnItem = MenuItemImage::create("common_tips_button_close_.png", "common_tips_button_close_.png", CC_CALLBACK_1(HeroInformationMenuLayer::Return, this)); // returnItem->setScale(2 - flexibleX ,2 - flexibleY); auto returnMenu = Menu::create(returnItem, NULL); float rmX = menuBG->getContentSize().width; float rmY = menuBG->getContentSize().height - returnItem->getContentSize().height / 2; returnMenu->setPosition(Vec2(rmX, rmY)); menuBG->addChild(returnMenu); log("%f,%f", rmX, menuBG->getContentSize().height / 2); //三个开关的实现 //属性 auto characterItem_a = MenuItemImage::create("ShuXing_a.png", "ShuXing_a.png"); auto characterItem_b = MenuItemImage::create("ShuXing_b.png", "ShuXing_b.png"); characterToggle = MenuItemToggle::createWithCallback(CC_CALLBACK_1(HeroInformationMenuLayer::toggleButton, this), characterItem_a, characterItem_b, NULL); characterToggle->setName("character"); //图鉴 auto illustratedHhandbook_a = MenuItemImage::create("TuJian_a.png", "TuJian_a.png"); auto illustratedHhandbook_b = MenuItemImage::create("TuJian_b.png", "TuJian_b.png"); illustratedHhandbookToggle = MenuItemToggle::createWithCallback(CC_CALLBACK_1(HeroInformationMenuLayer::toggleButton, this), illustratedHhandbook_a, illustratedHhandbook_b, NULL); illustratedHhandbookToggle->setName("illustratedHhandbook"); //技能 auto skill_a = MenuItemImage::create("JiNeng_a.png", "JiNeng_a.png"); auto skill_b = MenuItemImage::create("JiNeng_b.png", "JiNeng_b.png"); skillToggle = MenuItemToggle::createWithCallback(CC_CALLBACK_1(HeroInformationMenuLayer::toggleButton, this), skill_a, skill_b, NULL); skillToggle->setName("skill"); //把三个开关放到菜单中 auto toggleMenu = Menu::create(characterToggle, illustratedHhandbookToggle, skillToggle, NULL); float tmX = menuBG->getContentSize().width / 2; float tmY = characterItem_a->getContentSize().height / 1.5; toggleMenu->setPosition(Vec2(tmX, tmY)); toggleMenu->alignItemsHorizontally(); menuBG->addChild(toggleMenu); //加入主角图片 auto role = Sprite::create("SF_Image.png"); float rX = role->getContentSize().width / 1.5; float rY = menuBG->getContentSize().height - (role->getContentSize().height / 2); role->setPosition(Vec2(rX, rY)); menuBG->addChild(role); }
void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes) { //std::srand(time()); auto s = Director::getInstance()->getWinSize(); lastRenderedCount = 0; currentQuantityOfNodes = 0; quantityOfNodes = nNodes; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) { quantityOfNodes -= kNodesIncrease; if( quantityOfNodes < 0 ) quantityOfNodes = 0; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); std::srand(0); }); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", [&](Ref *sender) { quantityOfNodes += kNodesIncrease; if( quantityOfNodes > kMaxNodes ) quantityOfNodes = kMaxNodes; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); std::srand(0); }); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, nullptr); menu->alignItemsHorizontally(); menu->setPosition(Vec2(s.width/2, s.height/2+15)); addChild(menu, 1); auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Vec2(s.width/2, s.height/2-15)); addChild(infoLabel, 1, kTagInfoLayer); updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); std::srand(0); }
bool Scene5::init() { if (!Layer::init()) { return false; } auto item = MenuItemFont::create("Goto Scene6", CC_CALLBACK_1(Scene5::ChangeScene, this)); auto menu = Menu::create(item, NULL); menu->alignItemsHorizontally(); this->addChild(menu); return true; }
bool SceneGame::init(int level) { Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); //背景 auto bg = Sprite::create("homebg.png"); bg->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2)); bg->setScaleX(visibleSize.width / 640); bg->setScaleY(visibleSize.height / 960); addChild(bg); //标题 auto tile = Sprite::create("tile.png"); tile->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - 80 - tile->getContentSize().height / 2)); addChild(tile); //菜单按钮 auto Itemhome = MenuItemImage::create("HomeNormal.png", "HomeSelected.png", CC_CALLBACK_1(SceneGame::menuSelectCallback, this)); auto Itemone = MenuItemImage::create("OneNormal.png", "OneSelected.png", CC_CALLBACK_1(SceneGame::menuSelectCallback, this)); auto Itemtwo = MenuItemImage::create("TwoNormal.png", "TwoSelected.png", CC_CALLBACK_1(SceneGame::menuSelectCallback, this)); auto Itemthree = MenuItemImage::create("ThreeNormal.png", "ThreeSelected.png", CC_CALLBACK_1(SceneGame::menuSelectCallback, this)); auto Itemfour = MenuItemImage::create("FourNormal.png", "FourSelected.png", CC_CALLBACK_1(SceneGame::menuSelectCallback, this)); auto Itemfive = MenuItemImage::create("FiveNormal.png", "FiveSelected.png", CC_CALLBACK_1(SceneGame::menuSelectCallback, this)); Itemhome->setTag(0); Itemone->setTag(1); Itemtwo->setTag(2); Itemthree->setTag(3); Itemfour->setTag(4); Itemfive->setTag(5); auto menu = Menu::create(Itemhome, Itemone, Itemtwo, Itemthree, Itemfour, Itemfive, NULL); menu->alignItemsHorizontally(); menu->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + Itemhome->getContentSize().height / 2)); menu->setTag(888); this->addChild(menu, 1000); return true; }
void MenuLayer2::alignMenusH() { for(int i=0;i<2;i++) { auto menu = static_cast<Menu*>( getChildByTag(100+i) ); menu->setPosition( _centeredMenu ); if(i==0) { // TIP: if no padding, padding = 5 menu->alignItemsHorizontally(); auto p = menu->getPosition(); menu->setPosition(p + Vec2(0,30)); } else { // TIP: but padding is configurable menu->alignItemsHorizontallyWithPadding(40); auto p = menu->getPosition(); menu->setPosition(p - Vec2(0,30)); } } }
void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) { //srandom(0); subtestNumber = asubtest; _subTest = new SubTest; _subTest->initWithSubTest(asubtest, this); auto s = Director::getInstance()->getWinSize(); lastRenderedCount = 0; quantityNodes = 0; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(SpriteMainScene::onDecrease, this)); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(SpriteMainScene::onIncrease, this)); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(Point(s.width/2, s.height-65)); addChild(menu, 1); auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Point(s.width/2, s.height-90)); addChild(infoLabel, 1, kTagInfoLayer); // add menu auto menuLayer = new SpriteMenuLayer(true, TEST_COUNT, SpriteMainScene::_s_nSpriteCurCase); addChild(menuLayer, 1, kTagMenuLayer); menuLayer->release(); /** * auto test menu */ auto menuAutoTest = Menu::create(); menuAutoTest->setPosition( Point::ZERO ); MenuItemFont::setFontName("Arial"); MenuItemFont::setFontSize(24); MenuItemFont* autoTestItem = NULL; if (SpriteMainScene::_s_autoTest) { autoTestItem = MenuItemFont::create("Auto Test On",CC_CALLBACK_1(SpriteMainScene::onAutoTest, this)); } else { autoTestItem = MenuItemFont::create("Auto Test Off",CC_CALLBACK_1(SpriteMainScene::onAutoTest, this)); } autoTestItem->setTag(1); autoTestItem->setPosition(Point( s.width - 90, s.height / 2)); menuAutoTest->addChild(autoTestItem); addChild( menuAutoTest, 3, kTagAutoTestMenu ); // Sub Tests MenuItemFont::setFontSize(28); auto subMenu = Menu::create(); for (int i = 1; i <= 13; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(SpriteMainScene::testNCallback, this)); itemFont->setTag(i); subMenu->addChild(itemFont, 10); if( i<= 4) itemFont->setColor(Color3B(200,20,20)); else if(i <= 8) itemFont->setColor(Color3B(0,200,20)); else if( i<=12) itemFont->setColor(Color3B(0,20,200)); else itemFont->setColor(Color3B::GRAY); } subMenu->alignItemsHorizontally(); subMenu->setPosition(Point(s.width/2, 80)); addChild(subMenu, 2); // add title label auto label = LabelTTF::create(title(), "Arial", 40); addChild(label, 1); label->setPosition(Point(s.width/2, s.height-32)); label->setColor(Color3B(255,255,40)); // subtitle std::string strSubtitle = subtitle(); if( ! strSubtitle.empty() ) { auto l = LabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); addChild(l, 9999); l->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 60) ); } while(quantityNodes < nNodes) onIncrease(this); }
void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) { std::srand(0); _subtestNumber = asubtest; _subTest = new (std::nothrow) SubTest; _subTest->initWithSubTest(asubtest, this); auto s = Director::getInstance()->getWinSize(); _lastRenderedCount = 0; _quantityNodes = 0; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(SpriteMainScene::onDecrease, this)); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(SpriteMainScene::onIncrease, this)); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, nullptr); menu->alignItemsHorizontally(); menu->setPosition(Vec2(s.width/2, s.height-65)); addChild(menu, 1); auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Vec2(s.width/2, s.height-90)); addChild(infoLabel, 1, kTagInfoLayer); /** * auto test menu */ auto menuAutoTest = Menu::create(); menuAutoTest->setPosition( Vec2::ZERO ); MenuItemFont::setFontName("fonts/arial.ttf"); MenuItemFont::setFontSize(24); // Sub Tests MenuItemFont::setFontSize(28); auto subMenu = Menu::create(); for (int i = 1; i <= 13; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(SpriteMainScene::testNCallback, this)); itemFont->setTag(i); subMenu->addChild(itemFont, 10); if( i<= 4) itemFont->setColor(Color3B(200,20,20)); else if(i <= 8) itemFont->setColor(Color3B(0,200,20)); else if( i<=12) itemFont->setColor(Color3B(0,20,200)); else itemFont->setColor(Color3B::GRAY); } subMenu->alignItemsHorizontally(); subMenu->setPosition(Vec2(s.width/2, 80)); addChild(subMenu, 2); // add title label auto label = Label::createWithTTF(title(), "fonts/arial.ttf", 32); addChild(label, 1, kTagTitle); label->setPosition(Vec2(s.width/2, s.height-50)); // subtitle std::string strSubtitle = subtitle(); if( ! strSubtitle.empty() ) { auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/Thonburi.ttf", 16); addChild(l, 9999); l->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) ); } while(_quantityNodes < nNodes) onIncrease(this); }
void ParticleMainScene::initWithSubTest(int asubtest, int particles) { //srandom(0); isStating = false; subtestNumber = asubtest; auto s = Director::getInstance()->getWinSize(); lastRenderedCount = 0; quantityParticles = particles; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) { quantityParticles -= kNodesIncrease; if( quantityParticles < 0 ) quantityParticles = 0; updateQuantityLabel(); createParticleSystem(); }); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", [&](Ref *sender) { quantityParticles += kNodesIncrease; if( quantityParticles > kMaxParticles ) quantityParticles = kMaxParticles; updateQuantityLabel(); createParticleSystem(); }); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, nullptr); menu->alignItemsHorizontally(); menu->setPosition(Vec2(s.width/2, s.height/2+15)); addChild(menu, 1); auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Vec2(s.width/2, s.height - 90)); addChild(infoLabel, 1, kTagInfoLayer); // particles on stage auto labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.'); addChild(labelAtlas, 0, kTagLabelAtlas); labelAtlas->setPosition(Vec2(s.width-66,50)); // Sub Tests MenuItemFont::setFontSize(40); auto pSubMenu = Menu::create(); for (int i = 1; i <= MAX_SUB_TEST_NUM; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(ParticleMainScene::testNCallback, this)); itemFont->setTag(i); pSubMenu->addChild(itemFont, 10); if (i <= 3) { itemFont->setColor(Color3B(200,20,20)); } else { itemFont->setColor(Color3B(0,200,20)); } } pSubMenu->alignItemsHorizontally(); pSubMenu->setPosition(Vec2(s.width/2, 80)); addChild(pSubMenu, 2); auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32); addChild(label, 1, kTagTitle); label->setPosition(Vec2(s.width/2, s.height-50)); updateQuantityLabel(); createParticleSystem(); schedule(CC_SCHEDULE_SELECTOR(ParticleMainScene::step)); }
bool CouponListScene::init() { if (!Layer::init()) { return false; } auto screenSize = Director::getInstance()->getWinSize(); auto background = Sprite::create("menu-background.png"); addChild(background); background->setPosition(screenSize.width * 0.5f, screenSize.height * 0.5f); // my coupons label auto myCouponsLabel = Label::createWithTTF("My Coupons", "fonts/Marker Felt.ttf", screenSize.height * 0.067f); addChild(myCouponsLabel); myCouponsLabel->setAnchorPoint(Vec2(0.0f, 1.0f)); myCouponsLabel->setPosition(screenSize.width * 0.05f, screenSize.height * 0.95f); myCouponsLabel->setColor(Color3B(0x04, 0xCF, 0x92)); // logo auto logo = Sprite::create("logo.png"); addChild(logo); logo->setAnchorPoint(Vec2(1.0f, 1.0f)); logo->setPosition(screenSize.width * 0.95f, screenSize.height * 0.95f); // back button auto backLabel = Label::createWithTTF("Back", "fonts/Marker Felt.ttf", screenSize.height * 0.033f); auto backItem = MenuItemLabel::create(backLabel, CC_CALLBACK_1(CouponListScene::back, this)); backItem->setColor(Color3B(0x00, 0x00, 0x00)); backItem->setAnchorPoint(Vec2(0.0f, 0.0f)); auto backMenu = Menu::create(backItem, nullptr); addChild(backMenu); backMenu->setAnchorPoint(Vec2(0.0f, 1.0f)); backMenu->setPosition(screenSize.width * 0.05f, screenSize.height * 0.8f); // show used label and menu auto showUsedLabel = Label::createWithTTF("Show used?", "fonts/Marker Felt.ttf", screenSize.height * 0.033f); addChild(showUsedLabel); showUsedLabel->setAnchorPoint(Vec2(0.0f, 1.0f)); showUsedLabel->setPosition(screenSize.width * 0.05f, screenSize.height * 0.7f); showUsedLabel->setColor(Color3B(0x70, 0x0C, 0xB3)); auto onLabel = Label::createWithTTF("On", "fonts/Marker Felt.ttf", screenSize.height * 0.033f, Size::ZERO, TextHAlignment::CENTER); _onButton = MenuItemLabel::create(onLabel, CC_CALLBACK_1(CouponListScene::showUsed, this)); _onButton->setColor(Color3B(0x56, 0x4F, 0x57)); _onButton->setDisabledColor(Color3B(0x04, 0xCF, 0x92)); _onButton->setAnchorPoint(Vec2(0.5f, 1.0f)); _onButton->setEnabled(false); // we start with "show used?" enabled, so disable on button auto offLabel = Label::createWithTTF("Off", "fonts/Marker Felt.ttf", screenSize.height * 0.033f, Size::ZERO, TextHAlignment::CENTER); _offButton = MenuItemLabel::create(offLabel, CC_CALLBACK_1(CouponListScene::hideUsed, this)); _offButton->setColor(Color3B(0x56, 0x4F, 0x57)); _offButton->setDisabledColor(Color3B(0x04, 0xCF, 0x92)); _offButton->setAnchorPoint(Vec2(0.5f, 1.0f)); auto onOffMenu = Menu::create(_onButton, _offButton, nullptr); addChild(onOffMenu); onOffMenu->setAnchorPoint(Vec2(0.0f, 1.0f)); onOffMenu->setPosition(screenSize.width * 0.33f, screenSize.height * 0.70f); onOffMenu->alignItemsHorizontally(); // list of coupons createCouponList(); setKeypadEnabled(true); return true; }
//////////////////////////////////////////////////////// // // PerformanceContainerScene // //////////////////////////////////////////////////////// void PerformanceContainerScene::initWithQuantityOfNodes(unsigned int nNodes) { _type = 0; //srand(time()); auto s = Director::getInstance()->getWinSize(); // Title auto label = LabelTTF::create(title().c_str(), "Arial", 32); addChild(label, 1, TAG_TITLE); label->setPosition(Point(s.width/2, s.height-50)); // Subtitle std::string strSubTitle = subtitle(); if(strSubTitle.length()) { auto l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16); addChild(l, 1, TAG_SUBTITLE); l->setPosition(Point(s.width/2, s.height-80)); } lastRenderedCount = 0; currentQuantityOfNodes = 0; quantityOfNodes = nNodes; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) { quantityOfNodes -= kNodesIncrease; if( quantityOfNodes < 0 ) quantityOfNodes = 0; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); srand(0); }); decrease->setColor(Color3B(0,200,20)); _decrease = decrease; auto increase = MenuItemFont::create(" + ", [&](Ref *sender) { quantityOfNodes += kNodesIncrease; if( quantityOfNodes > kMaxNodes ) quantityOfNodes = kMaxNodes; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); srand(0); }); increase->setColor(Color3B(0,200,20)); _increase = increase; auto menu = Menu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(Point(s.width/2, s.height/2+15)); addChild(menu, 1); auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Point(s.width/2, s.height/2-15)); addChild(infoLabel, 1, kTagInfoLayer); auto menuLayer = new ContainerBasicLayer(true, MAX_LAYER, g_curCase); addChild(menuLayer); menuLayer->release(); printf("Size of Node: %lu\n", sizeof(Node)); int oldFontSize = MenuItemFont::getFontSize(); MenuItemFont::setFontSize(24); Vector<cocos2d::MenuItem *> toggleItems; generateTestFunctions(); CCASSERT(!_testFunctions.empty(), "Should not be empty after generate test functions"); for (const auto& f : _testFunctions) { toggleItems.pushBack(MenuItemFont::create(f.name)); } auto toggle = MenuItemToggle::createWithCallback([this](Ref* sender){ auto toggle = static_cast<MenuItemToggle*>(sender); this->_type = toggle->getSelectedIndex(); auto label = static_cast<LabelTTF*>(this->getChildByTag(TAG_SUBTITLE)); label->setString(StringUtils::format("Test '%s', See console", this->_testFunctions[this->_type].name)); this->updateProfilerName(); }, toggleItems); toggle->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); toggle->setPosition(VisibleRect::left()); _toggle = toggle; auto start = MenuItemFont::create("start", [this](Ref* sender){ auto director = Director::getInstance(); auto sched = director->getScheduler(); CC_PROFILER_PURGE_ALL(); sched->schedule(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this, 2, false); this->unscheduleUpdate(); this->scheduleUpdate(); this->_startItem->setEnabled(false); this->_stopItem->setEnabled(true); this->_toggle->setEnabled(false); this->_increase->setEnabled(false); this->_decrease->setEnabled(false); }); start->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT); start->setPosition(VisibleRect::right() + Point(0, 40)); _startItem = start; auto stop = MenuItemFont::create("stop", [this](Ref* sender){ auto director = Director::getInstance(); auto sched = director->getScheduler(); sched->unschedule(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this); this->unscheduleUpdate(); this->_startItem->setEnabled(true); this->_stopItem->setEnabled(false); this->_toggle->setEnabled(true); this->_increase->setEnabled(true); this->_decrease->setEnabled(true); }); stop->setEnabled(false); stop->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT); stop->setPosition(VisibleRect::right() + Point(0, -40)); _stopItem = stop; auto menu2 = Menu::create(toggle, start, stop, NULL); menu2->setPosition(Point::ZERO); addChild(menu2); MenuItemFont::setFontSize(oldFontSize); updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); }
void LabelMainScene::initWithSubTest(int nodes) { //srandom(0); auto s = Director::getInstance()->getWinSize(); _lastRenderedCount = 0; _quantityNodes = 0; _accumulativeTime = 0.0f; _labelContainer = Layer::create(); addChild(_labelContainer); MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(LabelMainScene::onDecrease, this)); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(LabelMainScene::onIncrease, this)); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(Vec2(s.width/2, s.height-65)); addChild(menu, 1); auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Vec2(s.width/2, s.height-90)); addChild(infoLabel, 1, kTagInfoLayer); // add menu auto menuLayer = new LabelMenuLayer(true, TEST_COUNT, LabelMainScene::_s_labelCurCase); addChild(menuLayer, 1, kTagMenuLayer); menuLayer->release(); /** * auto test menu */ auto menuAutoTest = Menu::create(); menuAutoTest->setPosition( Vec2::ZERO ); MenuItemFont::setFontName("fonts/arial.ttf"); MenuItemFont::setFontSize(24); MenuItemFont* autoTestItem = NULL; if (LabelMainScene::_s_autoTest) { autoTestItem = MenuItemFont::create("Auto Test On",CC_CALLBACK_1(LabelMainScene::onAutoTest, this)); } else { autoTestItem = MenuItemFont::create("Auto Test Off",CC_CALLBACK_1(LabelMainScene::onAutoTest, this)); } autoTestItem->setTag(1); autoTestItem->setPosition(Vec2( s.width - 90, s.height / 2)); autoTestItem->setColor(Color3B::RED); menuAutoTest->addChild(autoTestItem); addChild( menuAutoTest, 3, kTagAutoTestMenu ); _title = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32); addChild(_title, 1); _title->setPosition(Vec2(s.width/2, s.height-50)); while(_quantityNodes < nodes) onIncrease(this); }
void CameraCullingDemo::onEnter() { CameraBaseTest::onEnter(); schedule(schedule_selector(CameraCullingDemo::update), 0.0f); auto s = Director::getInstance()->getWinSize(); /*auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesBegan, this); listener->onTouchesMoved = CC_CALLBACK_2(Camera3DTestDemo::onTouchesMoved, this); listener->onTouchesEnded = CC_CALLBACK_2(Camera3DTestDemo::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);*/ auto layer3D=Layer::create(); addChild(layer3D,0); _layer3D=layer3D; // swich camera MenuItemFont::setFontName("fonts/arial.ttf"); MenuItemFont::setFontSize(20); auto menuItem1 = MenuItemFont::create("Switch Camera", CC_CALLBACK_1(CameraCullingDemo::switchViewCallback,this)); menuItem1->setColor(Color3B(0,200,20)); auto menu = Menu::create(menuItem1,NULL); menu->setPosition(Vec2::ZERO); menuItem1->setPosition(VisibleRect::left().x + 80, VisibleRect::top().y -70); addChild(menu, 1); // + - MenuItemFont::setFontSize(40); auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(CameraCullingDemo::delSpriteCallback, this)); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(CameraCullingDemo::addSpriteCallback, this)); increase->setColor(Color3B(0,200,20)); menu = Menu::create(decrease, increase, nullptr); menu->alignItemsHorizontally(); menu->setPosition(Vec2(s.width - 60, VisibleRect::top().y -70)); addChild(menu, 1); TTFConfig ttfCount("fonts/Marker Felt.ttf", 30); _labelSprite3DCount = Label::createWithTTF(ttfCount,"0 sprits"); _labelSprite3DCount->setColor(Color3B(0,200,20)); _labelSprite3DCount->setPosition(Vec2(s.width/2, VisibleRect::top().y -70)); addChild(_labelSprite3DCount); // aabb drawNode3D _drawAABB = DrawNode3D::create(); _drawAABB->setCameraMask((unsigned short) CameraFlag::USER1); addChild(_drawAABB); // frustum drawNode3D _drawFrustum = DrawNode3D::create(); _drawFrustum->setCameraMask((unsigned short) CameraFlag::USER1); addChild(_drawFrustum); // set camera switchViewCallback(this); // add sprite addSpriteCallback(nullptr); }
//////////////////////////////////////////////////////// // // ParticleMainScene // //////////////////////////////////////////////////////// void ParticleMainScene::initWithSubTest(int asubtest, int particles) { //srandom(0); subtestNumber = asubtest; auto s = Director::getInstance()->getWinSize(); lastRenderedCount = 0; quantityParticles = particles; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) { quantityParticles -= kNodesIncrease; if( quantityParticles < 0 ) quantityParticles = 0; updateQuantityLabel(); createParticleSystem(); }); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", [&](Ref *sender) { quantityParticles += kNodesIncrease; if( quantityParticles > kMaxParticles ) quantityParticles = kMaxParticles; updateQuantityLabel(); createParticleSystem(); }); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(Point(s.width/2, s.height/2+15)); addChild(menu, 1); auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Point(s.width/2, s.height - 90)); addChild(infoLabel, 1, kTagInfoLayer); // particles on stage auto labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.'); addChild(labelAtlas, 0, kTagLabelAtlas); labelAtlas->setPosition(Point(s.width-66,50)); // Next Prev Test auto menuLayer = new ParticleMenuLayer(true, TEST_COUNT, s_nParCurIdx); addChild(menuLayer, 1, kTagMenuLayer); menuLayer->release(); // Sub Tests MenuItemFont::setFontSize(40); auto pSubMenu = Menu::create(); for (int i = 1; i <= 6; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(ParticleMainScene::testNCallback, this)); itemFont->setTag(i); pSubMenu->addChild(itemFont, 10); if (i <= 3) { itemFont->setColor(Color3B(200,20,20)); } else { itemFont->setColor(Color3B(0,200,20)); } } pSubMenu->alignItemsHorizontally(); pSubMenu->setPosition(Point(s.width/2, 80)); addChild(pSubMenu, 2); auto label = LabelTTF::create(title().c_str(), "Arial", 32); addChild(label, 1); label->setPosition(Point(s.width/2, s.height-50)); updateQuantityLabel(); createParticleSystem(); schedule(schedule_selector(ParticleMainScene::step)); }
//////////////////////////////////////////////////////// // // NodeChildrenMainScene // //////////////////////////////////////////////////////// void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes) { //srand(time()); auto s = Director::getInstance()->getWinSize(); // Title auto label = LabelTTF::create(title().c_str(), "Arial", 32); addChild(label, 1); label->setPosition(Point(s.width/2, s.height-50)); // Subtitle std::string strSubTitle = subtitle(); if(strSubTitle.length()) { auto l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16); addChild(l, 1); l->setPosition(Point(s.width/2, s.height-80)); } lastRenderedCount = 0; currentQuantityOfNodes = 0; quantityOfNodes = nNodes; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) { quantityOfNodes -= kNodesIncrease; if( quantityOfNodes < 0 ) quantityOfNodes = 0; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); srand(0); }); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", [&](Ref *sender) { quantityOfNodes += kNodesIncrease; if( quantityOfNodes > kMaxNodes ) quantityOfNodes = kMaxNodes; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); srand(0); }); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(Point(s.width/2, s.height/2+15)); addChild(menu, 1); auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Point(s.width/2, s.height/2-15)); addChild(infoLabel, 1, kTagInfoLayer); auto menuLayer = new NodeChildrenMenuLayer(true, MAX_LAYER, g_curCase); addChild(menuLayer); menuLayer->release(); updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); srand(0); }
//////////////////////////////////////////////////////// // // PerformanceEventDispatcherScene // //////////////////////////////////////////////////////// void PerformanceEventDispatcherScene::initWithQuantityOfNodes(unsigned int nNodes) { _type = 0; srand((unsigned)time(nullptr)); auto s = Director::getInstance()->getWinSize(); // Title auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32); addChild(label, 1, TAG_TITLE); label->setPosition(Vec2(s.width/2, s.height-50)); // Subtitle std::string strSubTitle = subtitle(); if(strSubTitle.length()) { auto l = Label::createWithTTF(strSubTitle.c_str(), "fonts/Thonburi.ttf", 16); addChild(l, 1, TAG_SUBTITLE); l->setPosition(Vec2(s.width/2, s.height-80)); } _lastRenderedCount = 0; _currentQuantityOfNodes = 0; _quantityOfNodes = nNodes; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) { _quantityOfNodes -= kNodesIncrease; if( _quantityOfNodes < 0 ) _quantityOfNodes = 0; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); srand(0); }); decrease->setColor(Color3B(0,200,20)); _decrease = decrease; auto increase = MenuItemFont::create(" + ", [&](Ref *sender) { _quantityOfNodes += kNodesIncrease; if( _quantityOfNodes > kMaxNodes ) _quantityOfNodes = kMaxNodes; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); srand(0); }); increase->setColor(Color3B(0,200,20)); _increase = increase; auto menu = Menu::create(decrease, increase, nullptr); menu->alignItemsHorizontally(); menu->setPosition(Vec2(s.width/2, s.height/2+15)); addChild(menu, 1); auto infoLabel = Label::createWithTTF("0 listeners", "fonts/Marker Felt.ttf", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Vec2(s.width/2, s.height/2-15)); addChild(infoLabel, 1, kTagInfoLayer); auto menuLayer = new (std::nothrow) EventDispatcherBasicLayer(true, MAX_LAYER, g_curCase); addChild(menuLayer); menuLayer->release(); int oldFontSize = MenuItemFont::getFontSize(); MenuItemFont::setFontSize(24); Vector<cocos2d::MenuItem *> toggleItems; generateTestFunctions(); CCASSERT(!_testFunctions.empty(), "Should not be empty after generate test functions"); for (const auto& f : _testFunctions) { toggleItems.pushBack(MenuItemFont::create(f.name)); } auto reset = [this](){ // Removes all nodes for (auto& node : _nodes) { node->removeFromParent(); } _nodes.clear(); // Removes all fixed listeners for (auto& listener : _fixedPriorityListeners) { Director::getInstance()->getEventDispatcher()->removeEventListener(listener); } this->_lastRenderedCount = 0; }; auto toggle = MenuItemToggle::createWithCallback([=](Ref* sender){ auto toggle = static_cast<MenuItemToggle*>(sender); this->_type = toggle->getSelectedIndex(); auto label = static_cast<Label*>(this->getChildByTag(TAG_SUBTITLE)); label->setString(StringUtils::format("Test '%s', See console", this->_testFunctions[this->_type].name)); this->updateProfilerName(); reset(); }, toggleItems); toggle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); toggle->setPosition(VisibleRect::left()); _toggle = toggle; auto start = MenuItemFont::create("start", [this](Ref* sender){ auto director = Director::getInstance(); auto sched = director->getScheduler(); CC_PROFILER_PURGE_ALL(); sched->schedule(CC_SCHEDULE_SELECTOR(PerformanceEventDispatcherScene::dumpProfilerInfo), this, 2, false); this->unscheduleUpdate(); this->scheduleUpdate(); this->_startItem->setEnabled(false); this->_stopItem->setEnabled(true); this->_toggle->setEnabled(false); this->_increase->setEnabled(false); this->_decrease->setEnabled(false); }); start->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT); start->setPosition(VisibleRect::right() + Vec2(0, 40)); _startItem = start; auto stop = MenuItemFont::create("stop", [=](Ref* sender){ auto director = Director::getInstance(); auto sched = director->getScheduler(); sched->unschedule(CC_SCHEDULE_SELECTOR(PerformanceEventDispatcherScene::dumpProfilerInfo), this); this->unscheduleUpdate(); this->_startItem->setEnabled(true); this->_stopItem->setEnabled(false); this->_toggle->setEnabled(true); this->_increase->setEnabled(true); this->_decrease->setEnabled(true); reset(); }); stop->setEnabled(false); stop->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT); stop->setPosition(VisibleRect::right() + Vec2(0, -40)); _stopItem = stop; auto menu2 = Menu::create(toggle, start, stop, nullptr); menu2->setPosition(Vec2::ZERO); addChild(menu2); MenuItemFont::setFontSize(oldFontSize); updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); }
bool MainScene::init(){ if(!Scene::init()){ return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newAlwaysShow.plist"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("UI/res_fx/normal_bullet.plist"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newCommon.plist"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("newBattle.plist"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("nopack/qiancengta.plist");//出新英雄的背景 auto btnFrame_normal = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png"); auto btnFrame_clicked = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png"); auto btnFrame_normal2 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png"); auto btnFrame_clicked2 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png"); auto btnFrame_normal3 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png"); auto btnFrame_clicked3 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png"); auto btnFrame_normal4 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png"); auto btnFrame_clicked4 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png"); auto btnFrame_normal5 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_normal.png"); auto btnFrame_clicked5 = Sprite::createWithSpriteFrameName("btn_dibuzhukong_highlight.png"); auto liangshan = Sprite::createWithSpriteFrameName("btn_liangshan.png"); auto zhenrong = Sprite::createWithSpriteFrameName("icon_zhenrong.png"); auto zhengzhan = Sprite::createWithSpriteFrameName("icon_zhengzhan.png"); auto xingxia = Sprite::createWithSpriteFrameName("icon_xingxia.png"); auto shop = Sprite::createWithSpriteFrameName("icon_shangdian.png"); //加上下边框 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("gameFrame.plist"); auto upFrame = Sprite::createWithSpriteFrameName("icon_shanghuabian.png"); auto downFrame = Sprite::createWithSpriteFrameName("icon_xiahuabian.png"); downFrame->setPosition(visibleSize.width/2,downFrame->getContentSize().height/2); upFrame->setPosition(visibleSize.width/2,visibleSize.height-upFrame->getContentSize().height/2); this->addChild(downFrame,2); this->addChild(upFrame,2); //加入所有底层功能 auto liangshan2 = Sprite::createWithSpriteFrameName("btn_liangshan.png"); liangshan2->setScale(0.8f); btnFrame_normal->addChild(liangshan); btnFrame_clicked->addChild(liangshan2); auto btn1 = MenuItemSprite::create(btnFrame_normal,btnFrame_clicked,CC_CALLBACK_1(MainScene::bottomFunction,this)); liangshan->setPosition(btn1->getContentSize().width/2,btn1->getContentSize().height/2); liangshan2->setPosition(btn1->getContentSize().width/2,btn1->getContentSize().height/2); auto zhenrong2 = Sprite::createWithSpriteFrameName("icon_zhenrong.png"); zhenrong2->setScale(0.8f); btnFrame_normal2->addChild(zhenrong); btnFrame_clicked2->addChild(zhenrong2); auto btn2 = MenuItemSprite::create(btnFrame_normal2,btnFrame_clicked2,CC_CALLBACK_1(MainScene::bottomFunction,this)); zhenrong->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2); zhenrong2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2); auto zhengzhan2 = Sprite::createWithSpriteFrameName("icon_zhengzhan.png"); zhengzhan2->setScale(0.8f); btnFrame_normal3->addChild(zhengzhan); btnFrame_clicked3->addChild(zhengzhan2); auto btn3 = MenuItemSprite::create(btnFrame_normal3,btnFrame_clicked3,CC_CALLBACK_1(MainScene::bottomFunction,this)); zhengzhan->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2); zhengzhan2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2); auto xingxia2 = Sprite::createWithSpriteFrameName("icon_xingxia.png"); xingxia2->setScale(0.8f); btnFrame_normal4->addChild(xingxia); btnFrame_clicked4->addChild(xingxia2); auto btn4 = MenuItemSprite::create(btnFrame_normal4,btnFrame_clicked4,CC_CALLBACK_1(MainScene::bottomFunction,this)); xingxia->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2); xingxia2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2); auto shop2 = Sprite::createWithSpriteFrameName("icon_shangdian.png"); shop2->setScale(0.8f); btnFrame_normal5->addChild(shop); btnFrame_clicked5->addChild(shop2); auto btn5 = MenuItemSprite::create(btnFrame_normal5,btnFrame_clicked5,CC_CALLBACK_1(MainScene::bottomFunction,this)); shop->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2); shop2->setPosition(btn2->getContentSize().width/2,btn2->getContentSize().height/2); //liangshan1->setTag(11); /*auto menu2 = Menu::create(liangshan1,zhenrong1,zhengzhan1,xingxia1,shop1,NULL); menu2->alignItemsHorizontallyWithPadding(0.0f); menu2->setPosition(visibleSize.width/2,btn1->getContentSize().height/2+downFrame->getContentSize().height-2); this->addChild(menu2); */ menu1 = Menu::create(btn1,btn2,btn3,btn4,btn5,NULL); menu1->alignItemsHorizontally(); menu1->alignItemsHorizontallyWithPadding(0.0f); menu1->setPosition(visibleSize.width/2,btn1->getContentSize().height/2+downFrame->getContentSize().height-2); this->addChild(menu1,2,MAIN_MENU_TAG); //底层功能TAG btn1->setTag(11); btn2->setTag(12); btn3->setTag(13); btn4->setTag(14); btn5->setTag(15); //TO DO....阵型 & 武将列表 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("more.plist"); auto zhenxing = Sprite::createWithSpriteFrameName("icon_zhanghaoshezhi.png"); auto zhenxingitem = MenuItemSprite::create(zhenxing, zhenxing, CC_CALLBACK_1(MainScene::showZhenXing,this)); auto wujiang = Sprite::createWithSpriteFrameName("icon_tujian.png"); auto wujiangitem = MenuItemSprite::create(wujiang, wujiang, CC_CALLBACK_1(MainScene::showTeamList,this)); auto menu4 = Menu::create(zhenxingitem,wujiangitem,NULL); menu4->alignItemsHorizontally(); menu4->setPosition(visibleSize.width/4,194+zhenxing->getContentSize().height); this->addChild(menu4,2); //攻城列队 auto gongcheng = Sprite::createWithSpriteFrameName("icon_bangzhu.png"); auto gongchengitem = MenuItemSprite::create(gongcheng, gongcheng, CC_CALLBACK_1(MainScene::showGongchengTeam,this)); auto menu5 = Menu::create(gongchengitem,NULL); menu5->setPosition(Vec2::ZERO); gongchengitem->setPosition(visibleSize.width/2,194+zhenxing->getContentSize().height); this->addChild(menu5,2); //背景 auto bg = Sprite::create("building.jpeg"); bg->setPosition(visibleSize.width/2, visibleSize.height/2); this->addChild(bg,1); auto topleft = Sprite::createWithSpriteFrameName("bg-banner_top_left.png"); auto topright = Sprite::createWithSpriteFrameName("bg-banner_top_right.png"); topleft->setAnchorPoint(Vec2(0,1)); topright->setAnchorPoint(Vec2(1,1)); topleft->setPosition(0,visibleSize.height-upFrame->getContentSize().height+2); topright->setPosition(visibleSize.width,visibleSize.height-upFrame->getContentSize().height+2); this->addChild(topleft,2); this->addChild(topright,2); //用户等级,名字,银两,声望------------ char wenzi[32]; sprintf(wenzi,"%d",99); auto level = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24); auto name = Label::createWithTTF("十八罗汉", "字体/华文新魏.TTF", 24); level->setPosition(40,visibleSize.height-upFrame->getContentSize().height-topleft->getContentSize().height/4); name->setPosition(50+name->getContentSize().width/2+30,visibleSize.height-upFrame->getContentSize().height-topleft->getContentSize().height/4); this->addChild(level,3,USERLEVEL_TAG); this->addChild(name,3,USERNAME_TAG); sprintf(wenzi,"%d",99999); auto money = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24); money->setPosition(visibleSize.width/2+50+money->getContentSize().width/2,visibleSize.height-upFrame->getContentSize().height-topright->getContentSize().height*3/4); this->addChild(money,3,USERMONEY_TAG); sprintf(wenzi,"%d",99999); auto reputation = Label::createWithTTF(wenzi, "字体/华文新魏.TTF", 24); reputation->setPosition(visibleSize.width*3/4+50+reputation->getContentSize().width/2,visibleSize.height-upFrame->getContentSize().height-topright->getContentSize().height*3/4); this->addChild(reputation,3,USERREPUTATION_TAG); //抽将功能页面HelloWorldLayer加载,MainLayer没用可以删掉 //TO DO...抽装备选项 auto _HelloWorldLayer = HelloWorldLayer::create(); auto _MainLayer = MainLayer::create(); if(_HelloWorldLayer){ _HelloWorldLayer->setDelegator(_MainLayer); this->addChild(_HelloWorldLayer,1,HELLOWORLD_LAYER_TAG); } if(_MainLayer) this->addChild(_MainLayer,1); //载入数据----------------------- //string dou = FileUtils::getInstance()->fullPathForFilename("wholeheros.db"); //log("存放路径为%s",dou.c_str()); //string documentpath1 = FileUtils::getInstance()->fullPathForFilename("UserInfo.db"); log("存放路径为%s",documentpath1.c_str()); GameStat::getInstance()->readFromUserInfo("Users_Info", documentpath1.c_str()); GameStat::getInstance()->readFromUserHeros("User_hero", documentpath1.c_str(), 0); char sql[1024]; sprintf(sql, "select * from User_equip where username = \"%s\"", user_name.c_str());//根据用户名读取英雄 GameStat::getInstance()->readfromEquipInfo("User_equip", documentpath1.c_str(),sql); //将玩家信息:等级、名字、银两、声望、元宝等从服务器加载 MainScene::resetUserInfo(); //------------------------------- //载入攻城车 GongChengType gongcheng1; gongcheng1.engname = "gongchengche"; gongcheng1.type = 1; gongcheng1.attack = 210; gongcheng1.durable = 4; gongcheng1.attack_type = 1; gongcheng1.bullet_type = 1; GongChengType gongcheng2; gongcheng2.engname = "toushiche"; gongcheng2.type = 1; gongcheng2.attack = 240; gongcheng2.durable = 3; gongcheng2.attack_type = 1; gongcheng2.bullet_type = 1; GongChengType gongcheng3; gongcheng3.engname = "paoshiche"; gongcheng3.type = 1; gongcheng3.attack = 260; gongcheng3.durable = 3; gongcheng3.attack_type = 1; gongcheng3.bullet_type = 1; GongChengType gongcheng4; gongcheng4.engname = "nuche"; gongcheng4.type = 2; gongcheng4.attack = 210; gongcheng4.durable = 5; gongcheng4.attack_type = 1; gongcheng4.bullet_type = 2; GongChengType gongcheng5; gongcheng5.engname = "junuche"; gongcheng5.type = 2; gongcheng5.attack = 350; gongcheng5.durable = 3; gongcheng5.attack_type = 1; gongcheng5.bullet_type = 2; GongChengType gongcheng6; gongcheng6.engname = "liannu"; gongcheng6.type = 2; gongcheng6.attack = 200; gongcheng6.durable = 5; gongcheng6.attack_type = 3; gongcheng6.bullet_type = 2; GameStat::getInstance()->userqixie.push_back(gongcheng1); GameStat::getInstance()->userqixie.push_back(gongcheng2); GameStat::getInstance()->userqixie.push_back(gongcheng3); GameStat::getInstance()->userqixie.push_back(gongcheng4); GameStat::getInstance()->userqixie.push_back(gongcheng5); GameStat::getInstance()->userqixie.push_back(gongcheng6); //敌军守城器械赋值 GameStat::getInstance()->enemyCompeteQixie[0] = gongcheng6; GameStat::getInstance()->enemyCompeteQixie[0].position = 0; GameStat::getInstance()->enemyCompeteQixie[1] = gongcheng5; GameStat::getInstance()->enemyCompeteQixie[1].position = 1; GameStat::getInstance()->enemyCompeteQixie[2] = gongcheng4; GameStat::getInstance()->enemyCompeteQixie[2].position = 2; //进入新手指导 __NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(MainScene::receive_notice_from_battle), "newPlayer", NULL);//一般是从战斗场景跳回调用 if(in_newplayer_mode) MainScene::newPlayerStart(new_stage); return true; }