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; }
LayerColor* GameLayer::createLayer(const Size& size, Color4B color, Vec2 position){ LayerColor* layerColor = LayerColor::create(color, size.width, size.height); layerColor->setAnchorPoint(Vec2(0.5, 0.5)); layerColor->ignoreAnchorPointForPosition(false); layerColor->setPosition(position); return layerColor; }
bool SkillTableView::init() { if (!Node::init()) return false; LayerColor* bg = LayerColor::create(Color4B(255, 255, 255, 127), 450, 500); bg->setPosition(bg->getContentSize()/-2); this->addChild(bg, -1); CCLabelTTF* title = CCLabelTTF::create("技能列表", "fonts/Marker Felt.ttf", 40); title->setPosition(Point(bg->getContentSize().width/2, bg->getContentSize().height-30)); bg->addChild(title); ControlButton* button = ControlButton::create(Scale9Sprite::create("ui/closed_normal.png")); button->setBackgroundSpriteForState(Scale9Sprite::create("ui/closed_selected.png"), Control::State::HIGH_LIGHTED); button->setPreferredSize(Size(57, 58)); button->setPosition(ccpSub(ccpAdd(bg->getPosition(), bg->getContentSize()), button->getContentSize()/2)); this->addChild(button); button->addTargetWithActionForControlEvents(GAME_UILAYER, cccontrol_selector(GameInfoUIController::removeSmallMenuAndButton), Control::EventType::TOUCH_UP_INSIDE); // button->setTouchPriority(0); m_skillTableView = TableView::create(this, Size(420, 420)); m_skillTableView->setPosition(Point(15, 15)); // m_skillTableView->setDirection(kCCScrollViewDirectionVertical); m_skillTableView->setDelegate(this); // m_skillTableView->setVerticalFillOrder(kCCTableViewFillTopDown); bg->addChild(m_skillTableView); m_skillTableView->reloadData(); return true; }
void TDDHelperTest::testColor(Ref *sender) { LayerColor *layer; float width = 100; float height = 100; float x = 5; float y = 50; const int numColor = 5; Color3B colors[numColor] = { TDD_COLOR_BLACK, TDD_COLOR_WHITE, TDD_COLOR_BLUE1, TDD_COLOR_BLUE2, TDD_COLOR_GREEN1, }; // layer = LayerColor::create for(int i=0; i<numColor; i++) { Color3B color3B = colors[i]; Color4B color = Color4B(color3B); layer = LayerColor::create(color, width, height); layer->setPosition(x, y); addChild(layer); x += width; } }
void Ajustes::initFondoTemp(){ LayerColor *capaFondo = LayerColor::create(Color4B(25,78,121,255), visibleSize.width, visibleSize.height); capaFondo->setPosition(0,0); this->addChild(capaFondo,-1); fondoTemp = Sprite::create("mostrosity_dientes_d.png"); fondoTemp->setScale(escala); fondoTemp->setAnchorPoint(Vec2(0,0.5)); fondoTemp->setPosition(visibleSize.width/2,visibleSize.height/2); this->addChild(fondoTemp); fondoTemp = Sprite::create("mostrosity_dientes_d.png"); fondoTemp->setScale(escala); fondoTemp->setAnchorPoint(Vec2(1,0.5)); fondoTemp->setPosition(visibleSize.width/2,visibleSize.height/2); this->addChild(fondoTemp); altoIndividalCuadroJuego = visibleSize.height-((espacioBordesCuadro*2*escala)); anchoIndividualCuadroJuego = anchoNoLateralCE-(espacioBordesCuadro*2*escala); cuadroJuego = LayerGradient::create(Color4B(174,209,240,255),Color4B(174,209,240,255)); cuadroJuego->setContentSize(Size(anchoIndividualCuadroJuego,altoIndividalCuadroJuego)); cuadroJuego->setPosition(anchoLateralCE+(espacioBordesCuadro*escala),(espacioBordesCuadro*escala)); cuadroJuego->setZOrder(1); this->addChild(cuadroJuego); }
bool StageLayer::init() { LayerColor* shadow = LayerColor::create(Color4B(0,0,0,128)); shadow->setPosition(-540,-960); this->addChild(shadow,-2); bg = Sprite::create("dialog_background.png"); bg->setPositionY(100); this->addChild(bg); auto title = Sprite::create("situ_title.png"); title->setPositionY(350); this->addChild(title); list = MyListView::create(); list->stagelayer = this; for(int i=0;i<20;i++) { char str[100]; sprintf(str,"scoll%d",i+1); list->add_option(StringData::getInstance()->get_string(str)); } list->page = -1; this->addChild(list); back_btn = Sprite::create("chess_go_back.png"); back_btn->setPosition(-2600,350); this->addChild(back_btn); this->setPosition(540,960); auto dispatcher = Director::getInstance()->getEventDispatcher(); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); touchListener->onTouchBegan = CC_CALLBACK_2(StageLayer::onTouchBegan,this); touchListener->onTouchMoved = CC_CALLBACK_2(StageLayer::onTouchMoved,this); touchListener->onTouchEnded = CC_CALLBACK_2(StageLayer::onTouchEnded, this); dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); auto keyListener = EventListenerKeyboard::create(); keyListener->onKeyReleased = CC_CALLBACK_2(StageLayer::onKeyReleased, this); dispatcher->addEventListenerWithSceneGraphPriority(keyListener, this); return true; }
//TODO 屏蔽事件穿透 void BattleScene::createBottomBar() { LayerColor *bottom = LayerColor::create(Color4B(0, 0, 100, 100)); bottom->setContentSize(Size(WINSIZE.width, 120)); bottom->setPosition(Point(0, 0)); addChild(bottom); int totalCount = 11; int index = 0; Vector<MenuItem *> items; auto soldierInCamp = BattleData::getInstance()->getAttackSoldierInCamp(); map<int, vector<DSoldier *>>::iterator it; for(it=soldierInCamp.begin(); it!=soldierInCamp.end(); it++) { MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this)); item->setTag(it->first); items.pushBack(item); index++; //head Size size = item->getContentSize(); char img[20]; sprintf(img, "ui/%d.png", it->first / 100); auto head = Sprite::create(img); head->setAnchorPoint(Point(0.5, 0.5)); head->setPosition(size.width/2, size.height/2); item->addChild(head); char text[20]; sprintf(text, "X %d", it->second.size()); TTFConfig config("fonts/tahoma.ttf",16); auto count = Label::createWithTTF(config, text, TextHAlignment::LEFT); count->setPosition(size.width/2, size.height - count->getContentSize().height); item->addChild(count); //初始化为第一个兵种 if (m_selectedSoldierType <= 0) { m_selectedSoldierType = it->first; } } for (int i = index; i < totalCount; i++) { MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this)); item->setEnabled(false); items.pushBack(item); } Size bottomSize = bottom->getContentSize(); Sprite *spItem = Sprite::create("ui/618.0.png"); Size itemSize = spItem->getContentSize(); float padding = (bottomSize.width - itemSize.width * totalCount) / (totalCount + 1); UIRadioButton *radio = UIRadioButton::createWithArray(items); radio->alignItemsHorizontallyWithPadding(padding); radio->setPosition(Point(bottomSize.width / 2, bottomSize.height / 2)); radio->setSelectedIndex(0); bottom->addChild(radio); }
LayerColor* GameLayer::createBackgroundTile(float x, float y, Size size, Color4B color) { LayerColor* layerColor = LayerColor::create(color, size.width, size.height); layerColor->ignoreAnchorPointForPosition(false); layerColor->setAnchorPoint(Vec2(0.5, 0.5)); layerColor->setPosition(getTilePosition(x, y)); return layerColor; }
// 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 Game2048::initUI() { //scene -> gameLayer -> root / uiNode LayerColor *gameLayer = LayerColor::create(Color4B(0xff, 0xff, 0xf0, 0xff)); this->addChild(gameLayer); Node *root = Node::create(); gameLayer->addChild(root); Node *uiNode = Node::create(); gameLayer->addChild(uiNode); lblScore = Label::createWithTTF("", "fonts/Marker Felt.ttf", 24); lblScore->setPosition(Vec2(DISPLAY_CX, DISPLAY_HEIGHT * 4 / 5)); uiNode->addChild(lblScore); //root -> bg bgSize = DISPLAY_WIDTH - offsetW; LayerColor *bgLayer = LayerColor::create(Color4B(0xcd, 0xba, 0x96, 0xff), bgSize, bgSize); bgLayer->setPosition(Point(DISPLAY_CX,DISPLAY_CY)); bgLayer->setAnchorPoint(Point(0.5, 0.5)); bgLayer->ignoreAnchorPointForPosition(false); root->addChild(bgLayer); //NumNode numSize = (bgSize - offsetW) / s_row ; for (int i = 0; i < s_row; i++) { for (int j = 0; j < s_row; j++) { int numberX = numSize*(i+0.5) + DISPLAY_CX - bgSize/2 + offsetW/2 ; int numberY = numSize*(j+0.5) + DISPLAY_CY - bgSize/2 + offsetW/2; Node *numNode = Node::create(); numNode->setPosition(Point(numberX, numberY)); root->addChild(numNode); //bg LayerColor *numBg = LayerColor::create(Color4B(200, 190, 180, 0xff), numSize-offsetW/2, numSize-offsetW/2); numBg->setAnchorPoint(Point(0.5, 0.5)); numBg->ignoreAnchorPointForPosition(false); numNode->addChild(numBg); //card cardNumbers[i][j] = 0; Node *cardNode = createNumCard(cardNumbers[i][j]); cardNodes[i][j] = cardNode; numNode->addChild(cardNode); } } randomCreateNum(); randomCreateNum(); }
void TDDSubMenu::setupHeader(const Color4B &headerColor) { GLfloat parentH = this->getContentSize().height; GLfloat width = this->getContentSize().width; GLfloat height = kHeaderHeight; LayerColor *headerLayer = LayerColor::create(headerColor, width, height); Point pos = Point(0, parentH - height); headerLayer->setPosition(pos); this->addChild(headerLayer); // Setting Buttons float scale = TDDHelper::getBestScale(); // Size screenSize = TDDHelper::getScreenSize(); int midY = height/2; int buttonW = (int)(scale * 50); int buttonH = height; int leftButtonX = buttonW / 2; int rightButtonX = width - leftButtonX; int midX = width/2; Size size = Size(buttonW, buttonH); ControlButton *button; pos.x = leftButtonX; pos.y = midY; button = createButton("back", kActionTagBack, pos, size); headerLayer->addChild(button); mBackButton = button; pos.x = rightButtonX; pos.y = midY; button = createButton("hide", kActionTagToggle, pos, size); headerLayer->addChild(button); button->addTargetWithActionForControlEvents(this, cccontrol_selector(TDDSubMenu::touchUpInsideAction), Control::EventType::TOUCH_UP_INSIDE); mToggleButton = button; // Label Label *title = Label::createWithSystemFont("MENU", "Arial", 15); title->setColor(Color3B::WHITE); title->setPosition(Point(midX, midY)); headerLayer->addChild(title); // mHeaderLayer = headerLayer; }
void 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; }
// 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; }
void FriendListScene::buildScene() { _friendDictionary.clear(); _friendList.clear(); _tableView = NULL; _downloadCount = 0; const char* headerString = ""; switch (_selectedFriendCircle) { case ALL_FRIENDS: headerString = "All Friends"; break; case INSTALLED_ONLY: headerString = "Friends Playing Game"; break; case NON_PLAYING_ONLY: headerString = "Friends not Playing Game"; break; case MY_DEVICE_ONLY: #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) headerString = "Friends playing on iOS Device"; #else headerString = "Friends playing on Android Device"; #endif default: break; } //_friendList = CCArray::createWithCapacity(5); //_friendList->retain(); CCLOG("ALL Request count = %lu", _friendList.size()); // Add background layers to the scene. LayerColor *bg = LayerColor::create(Color4B(255, 255, 255, 255), AppDelegate::SCREEN_WIDTH, AppDelegate::SCREEN_HEIGHT); this->addChild(bg); LayerColor *secondBG = LayerColor::create(Color4B(95, 95, 95, 255), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), AppDelegate::SCREEN_HEIGHT - SCALED_VALUE(20.0f)); secondBG->setPosition(Point(SCALED_VALUE(10.0f), SCALED_VALUE(10.0f))); this->addChild(secondBG); // Set the table header. LayerColor *header = LayerColor::create(Color4B(66, 66, 66, 255), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), SCALED_VALUE(100.0f)); header->setAnchorPoint(Point(0, 0)); header->setPosition(Point(SCALED_VALUE(10.0f), AppDelegate::SCREEN_HEIGHT - SCALED_VALUE(110.0f))); this->addChild(header); // Set the header text. auto headerText = LabelTTF::create(headerString, "Arial", SCALED_VALUE(40.0f)); headerText->setAnchorPoint(Point(0.0f, 0.5f)); header->addChild(headerText); headerText->setPositionX(SCALED_VALUE(28.0f)); headerText->setPositionY(header->getContentSize().height/2); // Add back button go back to previous scene MenuItemImage *backButton = MenuItemImage::create(); backButton->setNormalSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_table_back_nrl")); backButton->setSelectedSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_table_back_prd")); backButton->setCallback(CC_CALLBACK_1(FriendListScene::backButtonPressed, this)); backButton->setAnchorPoint(Point(1.0f, 0.5)); Menu* backMenu = Menu::create(backButton, NULL); header->addChild(backMenu); backMenu->setPositionX(header->getContentSize().width - SCALED_VALUE(20.0f)); backMenu->setPositionY(header->getContentSize().height/2); // Create the table view. float tableHeight = bg->getContentSize().height - secondBG->getPositionY() - (header->getContentSize().height) - SCALED_VALUE(10); _tableView = TableView::create(this, Size(secondBG->getContentSize().width, tableHeight)); _tableView->setAnchorPoint(Point(0, 0.0)); _tableView->setDirection(ScrollView::Direction::VERTICAL); _tableView->setPosition(Point(SCALED_VALUE(10.0f), SCALED_VALUE(10))); _tableView->setDelegate(this); this->addChild(_tableView); }
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 QuestionContainerSprite::init() { if (Sprite::init()) { //Add label LabelTTF* label = LabelTTF::create("Answer 1", "Arial", 12); label->setTag(100); //Add the background Size size = Director::getInstance()->getWinSize(); Sprite* corner = Sprite::create("Images/bugs/corner.png"); int width = size.width * 0.9f - (corner->getContentSize().width * 2); int height = size.height * 0.15f - (corner->getContentSize().height * 2); LayerColor* layer = LayerColor::create(Color4B(255, 255, 255, 255 * .75), width, height); layer->setPosition(Point(-width / 2, -height / 2)); //First button is blue, //Second is red //Used for testing - change later static int a = 0; if (a == 0) label->setColor(Color3B::BLUE); else { log("Color changed"); label->setColor(Color3B::RED); } a++; addChild(layer); corner->setPosition(Point(-(width / 2 + corner->getContentSize().width / 2), -(height / 2 + corner->getContentSize().height / 2))); addChild(corner); Sprite* corner2 = Sprite::create("Images/bugs/corner.png"); corner2->setPosition(Point(-corner->getPosition().x, corner->getPosition().y)); corner2->setFlipX(true); addChild(corner2); Sprite* corner3 = Sprite::create("Images/bugs/corner.png"); corner3->setPosition(Point(corner->getPosition().x, -corner->getPosition().y)); corner3->setFlipY(true); addChild(corner3); Sprite* corner4 = Sprite::create("Images/bugs/corner.png"); corner4->setPosition(Point(corner2->getPosition().x, -corner2->getPosition().y)); corner4->setFlipX(true); corner4->setFlipY(true); addChild(corner4); Sprite* edge = Sprite::create("Images/bugs/edge.png"); edge->setScaleX(width); edge->setPosition(Point(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), corner->getPosition().y)); addChild(edge); Sprite* edge2 = Sprite::create("Images/bugs/edge.png"); edge2->setScaleX(width); edge2->setPosition(Point(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), -corner->getPosition().y)); edge2->setFlipY(true); addChild(edge2); Sprite* edge3 = Sprite::create("Images/bugs/edge.png"); edge3->setRotation(90); edge3->setScaleX(height); edge3->setPosition(Point(corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2))); addChild(edge3); Sprite* edge4 = Sprite::create("Images/bugs/edge.png"); edge4->setRotation(270); edge4->setScaleX(height); edge4->setPosition(Point(-corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2))); addChild(edge4); addChild(label); return true; } return false; }
TableViewCell* FriendListScene::tableCellAtIndex(TableView *table, ssize_t idx) { int index = idx; EziFacebookFriend* myFriend = (EziFacebookFriend*)_friendList.at(index); std::string friendName = myFriend->getName(); //const char* photoPath = myFriend->getPhotoPath().c_str(); bool toRequestForPhoto = false; if (myFriend->getPhoto() == nullptr) { toRequestForPhoto = true; //EziSocialObject::sharedObject()->getProfilePicForID(this, myFriend->getFBID(), SCALED_VALUE(85.0f), SCALED_VALUE(85.0f), false); } // Build the table cell. TableViewCell *cell = table->cellAtIndex(idx); if (cell == NULL) { cell = new TableViewCell(); cell->autorelease(); LayerColor* colorLayer = LayerColor::create(Color4B(100, 100, 100, 200), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), SCALED_VALUE(124.0f)); //cell->addChild(colorLayer); LayerColor* photoLayer = LayerColor::create(Color4B(255, 255, 255, 255), SCALED_VALUE(100.0f), SCALED_VALUE(100.0f)); photoLayer->setPosition(SCALED_VALUE(40.0f), SCALED_VALUE(12.0f)); cell->addChild(photoLayer); Sprite* userPhotoSprite = NULL; if (toRequestForPhoto) { userPhotoSprite = Sprite::create(); userPhotoSprite->setContentSize(Size(SCALED_VALUE(85.0f), SCALED_VALUE(85.0f))); } else { userPhotoSprite = myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this), false, SCALED_VALUE(85.0f), SCALED_VALUE(85.0f)); if (userPhotoSprite == nullptr) { userPhotoSprite = Sprite::create(); } } cell->addChild(userPhotoSprite); userPhotoSprite->setAnchorPoint(Point(0.0f, 0.0)); userPhotoSprite->cocos2d::CCNode::setPosition(SCALED_VALUE(47.0f), SCALED_VALUE(18.0f)); userPhotoSprite->setTag(TAG_PHOTO); auto message = LabelTTF::create(friendName.c_str(), "Arial", SCALED_VALUE(30.0f)); message->setAnchorPoint(Point(0, 0.5)); message->setPosition(Point(photoLayer->getContentSize().width + photoLayer->getPositionX() + SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); cell->addChild(message); message->setTag(TAG_MESSAGE); /* Sprite* consumedIcon = Sprite::createWithSpriteFrameName("green_tick"); consumedIcon->setAnchorPoint(Point(1.0, 0.5)); cell->addChild(consumedIcon); consumedIcon->setPosition(Point(colorLayer->getContentSize().width - SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); message->setTag(TAG_CONSUMED_ICON); MenuItemImage* useButton = MenuItemImage::create(); useButton->setSelectedSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_use_prd")); useButton->setNormalSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_use_nrl")); useButton->setAnchorPoint(Point(1.0, 0.5)); useButton->setTarget(this, menu_selector(FriendListScene::useRequest)); Menu* useMenu = Menu::create(useButton, NULL); cell->addChild(useMenu); useMenu->setPosition(Point(colorLayer->getContentSize().width - SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); useButton->setTag(index); useMenu->setTag(TAG_USE_MENU); */ } else { Sprite* cellProfilePic = (Sprite*)cell->getChildByTag(TAG_PHOTO); if (toRequestForPhoto == false) { //cellProfilePic->setTexture(Sprite::create(myFriend->getPhotoPath())->getTexture()); Sprite* tempSprite = myFriend->getPhoto(); if (myFriend->getPhoto() != nullptr) { cellProfilePic->setTexture(tempSprite->getTexture()); } else { myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this), false, SCALED_VALUE(85.0f), SCALED_VALUE(85.0f)); } } // Update the message Label. auto messageLabel = (LabelTTF*)cell->getChildByTag(TAG_MESSAGE); CCLOG("Friend Name = %s", friendName.c_str()); if (messageLabel) { messageLabel->setString(friendName.c_str()); } } return cell; }
void Akuerdate::JuegoTerminado(){ CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("ganar.mp3"); escuchadores = false; juegoTerminado = true; LayerColor *lyConseguido = LayerColor::create(Color4B(124,180,224,200)); lyConseguido->setPosition(cuadroJuego->getPosition()); lyConseguido->setContentSize(cuadroJuego->getContentSize()); lyConseguido->setLocalZOrder(20); addChild(lyConseguido); Sprite *foco = Sprite::create("preguntator_focoLuz.png"); foco->setScaleX(escalaAlta); foco->setScaleY(0); foco->setScaleZ(escalaAlta); foco->setAnchorPoint(Vec2(0.5,1)); foco->setPosition(lyConseguido->getContentSize().width/2,lyConseguido->getContentSize().height); lyConseguido->addChild(foco); //animacion foco ScaleTo *aniFoco = ScaleTo::create(0.7, escalaAlta); foco->runAction(aniFoco); __String *txtConsegido = __String::createWithFormat("%s %s",LanguageManager::getInstance()->getString("JUEGO_TX_FINAL_EXITO_2").c_str(),sNombreProfesion->getCString()); CCLabelTTF *txConseguido = CCLabelTTF::create(txtConsegido->getCString(), "HVD_Comic_Serif_Pro.ttf",120*escala,Size((visibleSize.width),(220*escala)*2), TextHAlignment::CENTER); txConseguido->setColor(Color3B(25,78,121)); txConseguido->setVerticalAlignment(TextVAlignment::CENTER); txConseguido->setAnchorPoint(Vec2(0.5,1)); txConseguido->setPosition(lyConseguido->getContentSize().width/2,visibleSize.height+(280*escala)); lyConseguido->addChild(txConseguido); //animacion textoConsegido MoveTo *aniTxConseguido = MoveTo::create(0.3, Vec2(lyConseguido->getContentSize().width/2,(lyConseguido->getContentSize().height))); txConseguido->runAction(aniTxConseguido); Sprite *pizzarra = Sprite::create("pizzarra_final_tiempo.png"); pizzarra->setScale(escalaAlta); pizzarra->setAnchorPoint(Vec2(0.5,1)); pizzarra->setPosition(visibleSize.width,(lyConseguido->getContentSize().height)-(txConseguido->getContentSize().height)); lyConseguido->addChild(pizzarra); CCLabelTTF *nAciertosPizarra = CCLabelTTF::create(reloj->getString(), "HVD_Comic_Serif_Pro.ttf",200,pizzarra->getContentSize(), TextHAlignment::CENTER); nAciertosPizarra->setColor(Color3B(255,255,255)); nAciertosPizarra->setVerticalAlignment(TextVAlignment::CENTER); nAciertosPizarra->setAnchorPoint(Vec2(0,0)); nAciertosPizarra->setPosition(0,0); pizzarra->addChild(nAciertosPizarra); //animacion pizzara MoveTo *aniPizzarra = MoveTo::create(0.3, Vec2(lyConseguido->getContentSize().width/2,pizzarra->getPositionY())); pizzarra->runAction(aniPizzarra); CGestorRecursos *gRecursos = new CGestorRecursos(); CRecurso *recursoAleatorio = gRecursos->obtenerRecursoBloqueadoAleatorio(); if(recursoAleatorio!=NULL){ gRecursos->quitarRecursoBloqueado(recursoAleatorio); Sprite *txPremio = Sprite::create("preguntator_finjuego_texto_inferior.png"); txPremio->setScale(escalaAlta); txPremio->setAnchorPoint(Vec2(0.5,0)); txPremio->setPosition(foco->getPositionX(),foco->getPositionY()-(foco->getContentSize().height*escalaAlta)); txPremio->setOpacity(0); lyConseguido->addChild(txPremio); //animacion txPremio Sequence *aniPremio1 = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); txPremio->runAction(aniPremio1); Sprite *premio = Sprite::create(recursoAleatorio->uri->getCString()); float escalaPremio = ((pizzarra->getContentSize().height*pizzarra->getScale())/2)/premio->getContentSize().height; float escalaPremioAncha = ((pizzarra->getContentSize().width*pizzarra->getScale()))/premio->getContentSize().width; if(escalaPremioAncha<escalaPremio) escalaPremio = escalaPremioAncha; premio->setScale(escalaPremio); premio->setAnchorPoint(Vec2(0.5,0)); premio->setPosition(txPremio->getPositionX(),txPremio->getPositionY()+(20*escalaPremio)+(txPremio->getContentSize().height*txPremio->getScaleY())); premio->setOpacity(0); //nuevo if(recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoOjos&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoAccesorio&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoDientes&&recursoAleatorio->tipoRecurso->getValue()!=Configuracion::rcsTipoColor) premio->runAction(TintTo::create(0,0,0,0)); lyConseguido->addChild(premio); string textoTraducido1 = LanguageManager::getInstance()->getString("kitDe"); string keyTexto2 = __String::createWithFormat("tipoRecurso%i",recursoAleatorio->tipoRecurso->getValue())->getCString(); string textoTraducido2 = LanguageManager::getInstance()->getString(keyTexto2); string textoFinal = __String::createWithFormat("%s %s",textoTraducido1.c_str(),textoTraducido2.c_str())->getCString(); CCLabelTTF *nAciertosPizarra = CCLabelTTF::create(textoFinal, "HVD_Comic_Serif_Pro.ttf",60,Size(lyConseguido->getContentSize().width,txPremio->getContentSize().height), TextHAlignment::CENTER); nAciertosPizarra->setColor(Color3B(229,57,57)); nAciertosPizarra->setVerticalAlignment(TextVAlignment::BOTTOM); nAciertosPizarra->setAnchorPoint(Vec2(0.5,0)); nAciertosPizarra->setPosition(txPremio->getContentSize().width/2,80); nAciertosPizarra->setOpacity(0); txPremio->addChild(nAciertosPizarra); Sequence *aniNAciertosPizarra = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); nAciertosPizarra->runAction(aniNAciertosPizarra); //nuevo Sequence *aniPremio = Sequence::create(DelayTime::create(0.7),FadeIn::create(1),NULL); premio->runAction(aniPremio); //efecto flotando RotateTo *rotarIzq = RotateTo::create(1, 10); RotateTo *rotarDer = RotateTo::create(1, -10); Sequence *total1 = Sequence::create(rotarIzq,rotarDer, NULL); Sequence *total2 = Sequence::create(rotarDer->clone(),rotarIzq->clone(), NULL); RepeatForever *repeticion1 = RepeatForever::create(total1); RepeatForever *repeticion2 = RepeatForever::create(total2); premio->runAction(repeticion1); } }
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; } }