void CocosToast::createToast(cocos2d::Node *node, const std::string &msg, const float &time,Vec2 point) { auto label = Label::createWithSystemFont(msg.c_str(), "Arial", 20); label->setColor(Color3B::WHITE); label->ignoreAnchorPointForPosition(false); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE); auto layer = LayerColor::create(Color4B(100,100,100,255)); layer->ignoreAnchorPointForPosition(false); layer->setAnchorPoint(Vec2::ANCHOR_MIDDLE); layer->setContentSize(label->getContentSize() + Size(20,15)); node->addChild(layer); node->addChild(label); layer->setPosition(point); label->setPosition(layer->getPosition()); auto seq1 = Sequence::create(FadeIn::create(time/5), DelayTime::create(time/5*1.5),FadeOut::create(time/5*2.5),CallFuncN::create(layer,callfuncN_selector(CocosToast::removeToast)),NULL); auto seq2 = Sequence::create(EaseSineIn::create(MoveBy::create(time/5, Vec2(0,50))),DelayTime::create(time/5*2),EaseSineOut::create(MoveBy::create(time/3, Vec2(0,-50))), NULL); auto spawn = Spawn::create(seq1, seq2, NULL); auto action = Repeat::create(spawn,1); layer->setOpacity(0); label->setOpacity(0); layer->runAction(action); label->runAction(action->clone()); }
//初始化场景,全部显显示从这里开始 bool Coordinate::init() { if(!Layer::init()){ return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); //创建一个Layer,size(屏幕的一半) auto red = LayerColor::create(Color4B(255, 100, 100, 128), visibleSize.width/2, visibleSize.height/2); red->ignoreAnchorPointForPosition(true); //忽略AnchorPoint,这个是AnchorPoint在左下角 red->ignoreAnchorPointForPosition(false); red->setAnchorPoint(Point(0.5,0.5));//设置Anchor Point在中间 red->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); //创建一个Layer,size(屏幕的1/4) auto green = LayerColor::create(Color4B(100, 255, 100, 128), visibleSize.width/4, visibleSize.height/4); green->ignoreAnchorPointForPosition(true); green->ignoreAnchorPointForPosition(false); green->setAnchorPoint(Point(1,1));//设置Anchor Point在右上角 red->addChild(green); this->addChild(red, 0); return true; }
//------------------------------------------------------------------ // // LayerTest2 // //------------------------------------------------------------------ void LayerTest2::onEnter() { LayerTest::onEnter(); auto s = Director::getInstance()->getWinSize(); auto layer1 = LayerColor::create( Color4B(255, 255, 0, 80), 100, 300); layer1->setPosition(Vec2(s.width/3, s.height/2)); layer1->ignoreAnchorPointForPosition(false); addChild(layer1, 1); auto layer2 = LayerColor::create( Color4B(0, 0, 255, 255), 100, 300); layer2->setPosition(Vec2((s.width/3)*2, s.height/2)); layer2->ignoreAnchorPointForPosition(false); addChild(layer2, 1); auto actionTint = TintBy::create(2, -255, -127, 0); auto actionTintBack = actionTint->reverse(); auto seq1 = Sequence::create( actionTint, actionTintBack, nullptr); layer1->runAction(seq1); auto actionFade = FadeOut::create(2.0f); auto actionFadeBack = actionFade->reverse(); auto seq2 = Sequence::create(actionFade, actionFadeBack, nullptr); layer2->runAction(seq2); }
void FontTest::showFont(const std::string& fontFile) { auto s = Director::getInstance()->getWinSize(); auto blockSize = Size(s.width/3, 200); float fontSize = 26; removeChildByTag(kTagLabel1, true); removeChildByTag(kTagLabel2, true); removeChildByTag(kTagLabel3, true); removeChildByTag(kTagLabel4, true); removeChildByTag(kTagColor1, true); removeChildByTag(kTagColor2, true); removeChildByTag(kTagColor3, true); auto top = Label::createWithSystemFont(fontFile, fontFile, 24); auto left = Label::createWithSystemFont("alignment left", fontFile, fontSize, blockSize, TextHAlignment::LEFT, verticalAlignment[vAlignIdx]); auto center = Label::createWithSystemFont("alignment center", fontFile, fontSize, blockSize, TextHAlignment::CENTER, verticalAlignment[vAlignIdx]); auto right = Label::createWithSystemFont("alignment right", fontFile, fontSize, blockSize, TextHAlignment::RIGHT, verticalAlignment[vAlignIdx]); auto leftColor = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height); auto centerColor = LayerColor::create(Color4B(200, 100, 100, 255), blockSize.width, blockSize.height); auto rightColor = LayerColor::create(Color4B(100, 100, 200, 255), blockSize.width, blockSize.height); leftColor->ignoreAnchorPointForPosition(false); centerColor->ignoreAnchorPointForPosition(false); rightColor->ignoreAnchorPointForPosition(false); top->setAnchorPoint(Vec2(0.5, 1)); left->setAnchorPoint(Vec2(0,0.5)); leftColor->setAnchorPoint(Vec2(0,0.5)); center->setAnchorPoint(Vec2(0,0.5)); centerColor->setAnchorPoint(Vec2(0,0.5)); right->setAnchorPoint(Vec2(0,0.5)); rightColor->setAnchorPoint(Vec2(0,0.5)); top->setPosition(s.width/2,s.height-20); left->setPosition(0,s.height/2); leftColor->setPosition(left->getPosition()); center->setPosition(blockSize.width, s.height/2); centerColor->setPosition(center->getPosition()); right->setPosition(blockSize.width*2, s.height/2); rightColor->setPosition(right->getPosition()); this->addChild(leftColor, -1, kTagColor1); this->addChild(left, 0, kTagLabel1); this->addChild(rightColor, -1, kTagColor2); this->addChild(right, 0, kTagLabel2); this->addChild(centerColor, -1, kTagColor3); this->addChild(center, 0, kTagLabel3); this->addChild(top, 0, kTagLabel4); }
bool PartyList::init() { CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); ignoreAnchorPointForPosition(false); m_cellWidth = 200 + 10; m_cellHeight = 200 + 10; int w = MAX(visibleSize.width/5, m_cellWidth ); //windows wants to use 'max' and mac wants to use 'maxf' int h = visibleSize.height; setContentSize(CCSizeMake(w, h)); ignoreAnchorPointForPosition(false); m_bg = CCLayerColor::create(ccc4(240,227,132,125), w, h); addChild(m_bg); for( int i=0; i< MAX_PARTY_MEMBERS; i++) { BaseRadioGroupLayer* radio = new BaseRadioGroupLayer(); radio->initRadioGroup("partyMemberSelect", i); //radio->addChild(view); radio->setAnchorPoint(ccp(0.5,0.5)); radio->setPosition( m_cellWidth/2, h - (m_cellHeight/2 + i*m_cellHeight)); radio->setContentSize(CCSizeMake(m_cellWidth, m_cellHeight)); addChild(radio); m_partyButtons[i] = radio; radio->setVisible(false); //all off until filled } for( int i=0; i< MAX_PARTY_MEMBERS; i++) { TouchableNode* btn = CreateSimpleButton("+ Party Member", "addPartyMemberBtn"); btn->setAnchorPoint(ccp(0.5,0.5)); btn->setPosition( m_cellWidth/2, h -( m_cellHeight/2 + i*m_cellHeight)); addChild(btn); m_partyAddButtons[i] = btn; btn->setVisible(true); btn->setTouchEnabled(true); } loadEntitiesForPartyJson(); return true; }
bool GameScene::init() { do { CC_BREAK_IF(!LayerColor::initWithColor(Color4B(180, 170, 160, 255))); srand(time(nullptr)); auto visibleSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); //背景 auto bg = LayerColor::create(Color4B::ORANGE, BACKGROUND_LENGTH, BACKGROUND_LENGTH); bg->setPosition(origin + Vec2(visibleSize)/2); //layer默认锚点不会影响坐标 bg->ignoreAnchorPointForPosition(false); this->addChild(bg, BACKGROUND_ZORDER, BACKGROUND_TAG); //循环添加格子背景 for (auto i = 0; i < BLOCK_COUNT; i++) { initBlock(i); } //随机产生两个块 createBlock(); createBlock(); //触摸事件 auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [&](Touch *touch, Event *) { m_startPos = touch->getLocation(); return m_canMove; }; listener->onTouchEnded = CC_CALLBACK_2(GameScene::moveBlock, this); //第二个参数表示:以谁为事件优先级的参照,它的优先级最高 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //创建遮罩层 auto propLayer = LayerColor::create(Color4B(100, 100, 100, 230)); auto lblMessage = Label::createWithTTF("", "Marker Felt.ttf", 48); lblMessage->setPosition(Vec2(propLayer->getContentSize())/2); lblMessage->setColor(Color3B::RED); propLayer->addChild(lblMessage, PROP_LAYER_LABEL_MESSAGE_ZORDER, PROP_LAYER_LABEL_MESSAGE_TAG); auto itemRestart = MenuItemLabel::create(Label::createWithTTF("RESTART", "Marker Felt.ttf", 36), CC_CALLBACK_1(GameScene::reStart, this)); itemRestart->setPosition(Vec2(propLayer->getContentSize()) / 2 + Vec2(0, -100)); itemRestart->setColor(Color3B::BLACK); auto menu = Menu::create(itemRestart, nullptr); menu->setPosition(Vec2::ZERO); propLayer->addChild(menu); this->addChild(propLayer, PROP_LAYER_ZORDER, PROP_LAYER_TAG); propLayer->setVisible(false); return true; } while (0); return false; }
bool CoordinateScene::init(){ Size visibleSize = Director::getInstance()->getVisibleSize(); auto red = LayerColor::create(Color4B(255,100,100,128),visibleSize.width/2,visibleSize.height/2); red->ignoreAnchorPointForPosition(false); red -> setAnchorPoint(Point(0.5,0.5)); auto green = LayerColor::create(Color4B(100,255,100,128),visibleSize.width/4,visibleSize.height/2); this -> addChild(green); this -> addChild(red,0); auto returnBtn = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(CoordinateScene::menuCloseCallBack,this)); returnBtn -> setPosition(Vec2(visibleSize.width - returnBtn -> getContentSize().width/2, visibleSize.height - returnBtn -> getContentSize().height/2)); auto menu = Menu::create(returnBtn,nullptr); menu -> setPosition(Vec2::ZERO); this -> addChild(menu,1); return true; }
bool CCControlSwitch::initWithMaskSprite(CCSprite *maskSprite, CCSprite * onSprite, CCSprite * offSprite, CCSprite * thumbSprite, CCLabelTTF* onLabel, CCLabelTTF* offLabel) { if (CCControl::init()) { CCAssert(maskSprite, "Mask must not be nil."); CCAssert(onSprite, "onSprite must not be nil."); CCAssert(offSprite, "offSprite must not be nil."); CCAssert(thumbSprite, "thumbSprite must not be nil."); setTouchEnabled(true); m_bOn = true; m_pSwitchSprite = new CCControlSwitchSprite(); m_pSwitchSprite->initWithMaskSprite(maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel); m_pSwitchSprite->setPosition(ccp (m_pSwitchSprite->getContentSize().width / 2, m_pSwitchSprite->getContentSize().height / 2)); addChild(m_pSwitchSprite); ignoreAnchorPointForPosition(false); setAnchorPoint(ccp (0.5f, 0.5f)); setContentSize(m_pSwitchSprite->getContentSize()); return true; } return false; }
CCCutTouchLayer::CCCutTouchLayer(): m_bClipsToBounds(false), m_bPreventTouch(true), m_nPriority(0) { ignoreAnchorPointForPosition(false); }
void CScrollViewContainer::reset() { removeAllChildrenWithCleanup(true); ignoreAnchorPointForPosition(true); setAnchorPoint(Vec2::ZERO); setPosition(Vec2::ZERO); }
bool CCtrlPage::init( void ) { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); m_nPageIndex = -1; ignoreAnchorPointForPosition(false); this->setAnchorPoint(ccp(m_fArchorPointX, m_fArchorPointY)); this->setPosition(ccp(m_fRealX, m_fRealY)); this->setContentSize(CCSizeMake(m_nWidth, m_nHeight)); setTouchPriority(g_nListTouchPri); setTouchEnabled(true); CCSize sizeView = CCSizeMake(getWidth(), getHeight()); CCScrollView* pView = CCScrollView::create(sizeView); CC_BREAK_IF(NULL == pView); setScrollView(pView); m_pScrollView->setContentOffset(CCPointZero); m_pScrollView->setTouchEnabled(true); m_pScrollView->setDelegate(this); m_pScrollView->setDirection(kCCScrollViewDirectionHorizontal); this->addChild(m_pScrollView); bRet = true; } while (0); return bRet; }
bool SpellDiagramNode::init() { setAnchorPoint(ccp(0.5f,0.5f)); ignoreAnchorPointForPosition(false); //setContentSize(CCSizeMake(100,100)); size = DSIZE; m_spellParts_Mods = JsonManager::get()->getJson("SpellParts_Mods"); m_spellParts_Effects = JsonManager::get()->getJson("SpellParts_Effects"); //ReadFileToJson( "spellParts.json" ); m_spellDiagrams = ReadFileToJson("spellDiagrams.json"); if( m_spellDiagrams.isMember("diagrams") ) { m_spellDiagrams = m_spellDiagrams["diagrams"]; } EventBus::game()->addListener("slotMenuCancel", this, callfuncO_selector(SpellDiagramNode::onMenuCancel)); EventBus::game()->addListener("slotMenuMod", this, callfuncO_selector(SpellDiagramNode::onMenuMod)); EventBus::game()->addListener("slotMenuEff", this, callfuncO_selector(SpellDiagramNode::onMenuEff)); setTouchEnabled(true); return true; }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); LevelData data = {}; data.rows = 4; data.columns = 2; auto card = MemoryCardLevel::create(data); auto levelSize = card->getContentSize(); card->ignoreAnchorPointForPosition(false); card->setAnchorPoint(Vec2(0.5, 0.5)); card->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2)); auto scale = visibleSize.height/levelSize.height; card->setScale(scale); this->addChild(card); return true; }
void NumberLabel::setNum(const int number) { if (_number != number) { _number = number; _node->removeAllChildren(); int temp = number; std::vector<int> digitNumbers; while(temp>0) { digitNumbers.push_back(temp%10); temp /= 10; } setContentSize(Size(_numWidth*digitNumbers.size(), _contentSize.height)); int dsize=digitNumbers.size(); for(int i=0; i!=dsize; i++) { temp = digitNumbers[i]; auto sp = Sprite::createWithSpriteFrame(SpriteFrame::createWithTexture(_texture, Rect(temp*_numWidth,0, _numWidth, _texture->getContentSize().height))); sp->ignoreAnchorPointForPosition(true); sp->setPositionX((dsize-i-1)*_numWidth); _node->addChild(sp); } } }
void ControllerFallingMode::autoPlay() { for (int i = 0; i < trackCount; i++) { for (vector<NoteObj>::iterator iter = notesInTrack[i].begin(); iter != notesInTrack[i].end(); iter++) { if (iter->info.startTime <= curTime && !iter->hitting) { iter->hitting = true; pAudioSystem->playSFX(0); auto hitEffect = Sprite::create("image/FallingHitLight.png"); hitEffect->ignoreAnchorPointForPosition(false); hitEffect->setAnchorPoint(Point(0.5, 0.25)); hitEffect->setOpacity(255); hitEffect->setPosition(Point(trackWidth*(i + 0.5), visibleSize.height / 8)); hitEffect->setScale(2, 0); //sprintf_s(name, "hit%d", i); pPanelFrame->addChild(hitEffect); hitEffect->runAction( Sequence::createWithTwoActions( ScaleTo::create(0.15, 0, 1), RemoveSelf::create() ) ); } } } }
void SudokuBox::refreshErrorTipsLayer() { auto it = m_setErrors.begin(); for (; it != m_setErrors.end(); ++it) { int pos = *it; if (m_mapErrorMask.find(pos) == m_mapErrorMask.end()) { //add error mask over the sprite auto mask = Sprite::createWithSpriteFrame( SpriteFrameCache::getInstance()->getSpriteFrameByName(FRAME_NAME[ERROR_MASK_INDEX]) ); mask->ignoreAnchorPointForPosition(false); mask->setAnchorPoint(Vec2(0, 1)); mask->setPosition(Vec2((pos % m_iCols) * CELL_SIZE, (m_iRows - pos / m_iCols) * CELL_SIZE)); this->addChild(mask, 1); //add the mask to the position-mask map m_mapErrorMask[pos] = mask; } } //remove those mask which is not error any longer. auto mit = m_mapErrorMask.begin(); while (mit != m_mapErrorMask.end()) { if (m_setErrors.find(mit->first) == m_setErrors.end()) { this->removeChild(mit->second, true); auto tmp = mit; mit++; m_mapErrorMask.erase(tmp); } else { mit++; } } }
bool GameElement::init() { if (!Layer::init()) { return false; } // valid anchor point ignoreAnchorPointForPosition(false); // get the side length _sideLen = (FieldWidth - (DIMENSION + 1)*ElemSpace)/DIMENSION; // create element _elem = Sprite::create(); _elem->setColor(Color3B::GRAY); _elem->setTextureRect(Rect(0, 0, _sideLen, _sideLen)); _elem->setAnchorPoint(Vec2(0, 0)); // add number _numberLabel = Label::createWithTTF("","fonts/Marker Felt.ttf", 90); _numberLabel->setAnchorPoint(Vec2(0.5, 0.5)); _numberLabel->setPosition(_elem->getContentSize().width/2, _elem->getContentSize().height/2); _numberLabel->setTextColor(Color4B::ORANGE); _numberLabel->setVisible(false); _elem->addChild(_numberLabel); setContentSize(Size(_sideLen, _sideLen)); this->setColor(Color3B::WHITE); this->setAnchorPoint(Point(0.5, 0.5)); this->setPosition(Point((_pos.x + 0.5)*_sideLen + ElemSpace * (_pos.x + 1), (3-_pos.y+0.5)*_sideLen + ElemSpace * (3 - _pos.y + 1))); addChild(_elem); return true; }
bool ControlSwitch::initWithMaskSprite(Sprite *maskSprite, Sprite * onSprite, Sprite * offSprite, Sprite * thumbSprite, LabelTTF* onLabel, LabelTTF* offLabel) { if (Control::init()) { CCASSERT(maskSprite, "Mask must not be nil."); CCASSERT(onSprite, "onSprite must not be nil."); CCASSERT(offSprite, "offSprite must not be nil."); CCASSERT(thumbSprite, "thumbSprite must not be nil."); setTouchEnabled(true); _on = true; _switchSprite = new ControlSwitchSprite(); _switchSprite->initWithMaskSprite(maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel); _switchSprite->setPosition(Point(_switchSprite->getContentSize().width / 2, _switchSprite->getContentSize().height / 2)); addChild(_switchSprite); ignoreAnchorPointForPosition(false); setAnchorPoint(Point(0.5f, 0.5f)); setContentSize(_switchSprite->getContentSize()); return true; } return false; }
void SportsLayer::drowFisrt(Layer* node,Vec2 p){ //黑色:RGB 000 float width=Actual_x*0.8f; float hight=Actual_y*0.8f; int fontsize=22; if(vsion==1){ width=Actual_x*0.8f; hight=Actual_y*0.8f; }else if(vsion==2){ width=525; hight=450; fontsize=20; } auto scal9=Layer::create(); scal9->setContentSize(Size(width,hight));// scal9->ignoreAnchorPointForPosition(false); scal9->setAnchorPoint(Vec2(0.5,0.5)); scal9->setPosition(p); node->addChild(scal9,1); l_one=scal9; auto sm1=Label::createWithSystemFont(FX::StringsMap::getValue("shuoming1"),"Arial",fontsize); sm1->setColor(Color3B(0,0,0)); sm1->setPosition(Vec2(sm1->getContentSize().width/2+20,hight*0.87)); scal9->addChild(sm1); auto sm2=Label::createWithSystemFont(FX::StringsMap::getValue("shuoming2"),"Arial",fontsize); sm2->setColor(Color3B(0,0,0)); sm2->setPosition(Vec2(sm2->getContentSize().width/2+20,hight*0.81)); scal9->addChild(sm2); auto sm3=Label::createWithSystemFont(FX::StringsMap::getValue("shuoming3"),"Arial",fontsize,Size(width-40,0),TextHAlignment::LEFT); sm3->setColor(Color3B(0,0,0)); sm3->setPosition(Vec2(sm3->getContentSize().width/2+20,hight*0.69)); scal9->addChild(sm3); string name_str=""; if(NetmsgManger::getNetManager()->mark==1){ name_str=NetmsgManger::getNetManager()->getMy_name(); }else{ schedule(schedule_selector(SportsLayer::get_myZm), 0.5f); rla=Label::createWithSystemFont("","Arial",24); rla->setColor(Color3B(0,0,0)); rla->setPosition(Vec2(scal9->getContentSize().width/2,scal9->getContentSize().height/2)); scal9->addChild(rla); } //我的组名 name=Label::createWithSystemFont(name_str,"Arial",fontsize); name->setColor(Color3B(0,0,0)); name->setPosition(width/2,hight*0.6); scal9->addChild(name); // }
bool Splash::init(){ if(!Layer::init()) return false; auto sprite = Sprite::create("Splash.png"); addChild(sprite); sprite->ignoreAnchorPointForPosition(true); scheduleOnce(schedule_selector(Splash::updateOnce), 1.2f); return true; }
NS_CC_GUI_BEGIN #define GRID_CELL_MARGIN 2 GridViewCell::GridViewCell() { ignoreAnchorPointForPosition(false); }
bool ControlSlider::initWithSprites(Sprite * backgroundSprite, Sprite* progressSprite, Sprite* thumbSprite, Sprite* selectedThumbSprite) { if (Control::init()) { CCASSERT(backgroundSprite, "Background sprite must be not nil"); CCASSERT(progressSprite, "Progress sprite must be not nil"); CCASSERT(thumbSprite, "Thumb sprite must be not nil"); CCASSERT(selectedThumbSprite, "Thumb sprite must be not nil"); if (backgroundSprite == nullptr || progressSprite == nullptr || thumbSprite == nullptr || selectedThumbSprite == nullptr) { return false; } ignoreAnchorPointForPosition(false); this->setBackgroundSprite(backgroundSprite); this->setProgressSprite(progressSprite); this->setThumbSprite(thumbSprite); this->setSelectedThumbSprite(selectedThumbSprite); // Defines the content size Rect maxRect = ControlUtils::RectUnion(backgroundSprite->getBoundingBox(), thumbSprite->getBoundingBox()); setContentSize(Size(maxRect.size.width, maxRect.size.height)); // Add the slider background _backgroundSprite->setAnchorPoint(Vec2(0.5f, 0.5f)); _backgroundSprite->setPosition(this->getContentSize().width / 2, this->getContentSize().height / 2); addChild(_backgroundSprite); // Add the progress bar _progressSprite->setAnchorPoint(Vec2(0.0f, 0.5f)); _progressSprite->setPosition(0.0f, this->getContentSize().height / 2); addChild(_progressSprite); // Add the slider thumb _thumbSprite->setPosition(0.0f, this->getContentSize().height / 2); addChild(_thumbSprite); _selectedThumbSprite->setPosition(0.0f, this->getContentSize().height / 2); _selectedThumbSprite->setVisible(false); addChild(_selectedThumbSprite); // Init default values _minimumValue = 0.0f; _maximumValue = 1.0f; setValue(_minimumValue); return true; } else { return false; } }
bool Building::initWithFile( const char* filename,const int gridCount ) { if (gridCount >= 2) { setGrassBg(Sprite::create(BuildingCommon::getGrassNameFromGridCount(gridCount))); getGrassBg()->setScale(0.5f); addChild(getGrassBg(),-1); } setBuildingArmature(Armature::create(filename)); getBuildingArmature()->setScale(0.5f); addChild(getBuildingArmature()); ignoreAnchorPointForPosition(false); setAnchorPoint(Point(0.5, 0)); m_nGridCount = gridCount; setContentSize(Size(UNIT_WIDTH*2*gridCount*2, UNIT_HEIGHT*2*gridCount*2)); if (getGrassBg()) { getGrassBg()->setPosition(Point(getContentSize().width /2,getContentSize().height / 2)); } getBuildingArmature()->setPosition(Point(getContentSize().width /2,0)); setArr1(CCSprite::create("ui/arr1.png")); setArr2(CCSprite::create("ui/arr2.png")); setArr3(CCSprite::create("ui/arr3.png")); setArr4(CCSprite::create("ui/arr4.png")); Size arrsize = getArr1()->getContentSize(); //log("%f %f",arrsize.width,arrsize.height); getArr1()->setPosition(Point(getContentSize().width / 4 * 3 + arrsize.width / 4,getContentSize().height / 4 * 3 + arrsize.height /4 )); getArr2()->setPosition(Point(getContentSize().width / 4 - arrsize.width / 4,getContentSize().height / 4 * 3 + arrsize.height /4 )); getArr3()->setPosition(Point(getContentSize().width / 4 * 3 + arrsize.width / 4 ,getContentSize().height / 4 - arrsize.height /4 )); getArr4()->setPosition(Point(getContentSize().width / 4 - arrsize.width / 4 ,getContentSize().height / 4 - arrsize.height /4)); addChild(getArr1()); addChild(getArr2()); addChild(getArr3()); addChild(getArr4()); getArr1()->setVisible(false); getArr2()->setVisible(false); getArr3()->setVisible(false); getArr4()->setVisible(false); setSharkAction(); setBigerAction(); return true; }
void BattleFieldUI::showVictoryUI() {//show the victory UI when win //diable AI //color layer auto layer = LayerColor::create(Color4B(10, 10, 10, 150)); layer->ignoreAnchorPointForPosition(false); layer->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 0)); //add victory auto victory = Sprite::createWithSpriteFrameName("victory.png"); victory->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 3)); victory->setScale(0.1); layer->addChild(victory, 1); layer->setGlobalZOrder(100); victory->setGlobalZOrder(100); //victory runaction auto action = EaseElasticOut::create(ScaleTo::create(1.5, 1)); victory->runAction(action); auto listener = EventListenerTouchOneByOne::create(); //touch event listener->onTouchBegan = [](Touch*, Event*) { return true; }; listener->onTouchEnded = [this](Touch*, Event*) { //clear GlobalVaribals HeroPool.clear(); DragonPool.clear(); SlimePool.clear(); RatPool.clear(); BossPool.clear(); PigletPool.clear(); HeroManager.clear(); MonsterManager.clear(); GameMaster::reset(); //stop schedule currentLayer->unscheduleUpdate(); Director::getInstance()->getScheduler()->unschedule("gameController", currentLayer); //stop sound experimental::AudioEngine::stop(AUDIO_ID.BATTLEFIELDBGM); //replace scene Director::getInstance()->replaceScene(ChooseRoleScene::createScene()); }; victory->setCameraMask(2); auto eventDispatcher = layer->getEventDispatcher(); eventDispatcher->addEventListenerWithSceneGraphPriority(listener, layer); addChild(layer); }
bool BBAbstractSceneView::init() { bool bRet = CCLayer::init(); if(bRet) { ignoreAnchorPointForPosition(false); setAnchorPoint(CCPointZero); setPosition(CCPointZero); } return bRet; };
bool MyControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprite* backgroundSprite,bool isSallowTouch) { if (init(isSallowTouch)) { CCASSERT(node != nullptr, "node must not be nil."); LabelProtocol* label = dynamic_cast<LabelProtocol*>(node); CCASSERT(backgroundSprite != nullptr, "Background sprite must not be nil."); CCASSERT(label != nullptr, "label must not be nil."); _parentInited = true; _isPushed = false; // Adjust the background image by default setAdjustBackgroundImage(true); setPreferredSize(Size::ZERO); // Zooming button by default _zoomOnTouchDown = true; _scaleRatio = 1.1f; // Set the default anchor point ignoreAnchorPointForPosition(false); setAnchorPoint(Vec2::ANCHOR_MIDDLE); // Set the nodes setTitleLabel(node); setBackgroundSprite(backgroundSprite); // Set the default color and opacity setColor(Color3B::WHITE); setOpacity(255.0f); setOpacityModifyRGB(true); // Initialize the dispatch table setTitleForState(label->getString(), Control::State::NORMAL); setTitleColorForState(node->getColor(), Control::State::NORMAL); setTitleLabelForState(node, Control::State::NORMAL); setBackgroundSpriteForState(backgroundSprite, Control::State::NORMAL); setLabelAnchorPoint(Vec2::ANCHOR_MIDDLE); // Layout update needsLayout(); return true; } //couldn't init the Control else { return false; } }
Scene* IntroLayer::createScene() { Size winSize = Director::getInstance()->getWinSize(); auto scene = Scene::create(); auto bgColorLayer = LayerColor::create(ccc4(0xff, 0xcc, 0x00, 255),winSize.width, winSize.height); bgColorLayer->ignoreAnchorPointForPosition(false); bgColorLayer->setPosition(Point(winSize.width/2,winSize.height/2)); scene->addChild(bgColorLayer); //±³¾°Æ½ÆÌ auto layer = IntroLayer::create(); scene->addChild(layer); return scene; }
bool RankTexture::init() { if (!Layer::init()) { return false; } ignoreAnchorPointForPosition(false); setAnchorPoint(Vec2(0.5, 0.5)); setContentSize(Size(0, 0)); return true; }
bool Bug1159Layer::init() { if (BugsTestBaseLayer::init()) { Director::getInstance()->setDepthTest(true); auto s = Director::getInstance()->getWinSize(); auto background = LayerColor::create(Color4B(255, 0, 255, 255)); addChild(background); auto sprite_a = LayerColor::create(Color4B(255, 0, 0, 255), 700, 700); sprite_a->setAnchorPoint(Point(0.5f, 0.5f)); sprite_a->ignoreAnchorPointForPosition(false); sprite_a->setPosition(Point(0.0f, s.height/2)); addChild(sprite_a); sprite_a->runAction(RepeatForever::create(Sequence::create( MoveTo::create(1.0f, Point(1024.0f, 384.0f)), MoveTo::create(1.0f, Point(0.0f, 384.0f)), NULL))); auto sprite_b = LayerColor::create(Color4B(0, 0, 255, 255), 400, 400); sprite_b->setAnchorPoint(Point(0.5f, 0.5f)); sprite_b->ignoreAnchorPointForPosition(false); sprite_b->setPosition(Point(s.width/2, s.height/2)); addChild(sprite_b); auto label = MenuItemLabel::create(Label::createWithSystemFont("Flip Me", "Helvetica", 24), CC_CALLBACK_1(Bug1159Layer::callBack, this) ); auto menu = Menu::create(label, NULL); menu->setPosition(Point(s.width - 200.0f, 50.0f)); addChild(menu); return true; } return false; }
void BBUnitSprite::createElements() { // if(!m_pEntity || !m_pUnitVisualMode) return; if(!m_pUnitVisualMode) return; if(isRunning()) return; this->removeAllChildren(); //创建内容 for(int i = 0; i < m_pUnitVisualMode->states_size(); i ++) { RTSUnitVisualStateModel* stateModel = m_pUnitVisualMode->mutable_states(i); if(stateModel->state() != m_nState) continue; CCPoint a = CCPointZero; CCPoint p = CCPointZero; CCSize s = CCSizeZero; s.width = stateModel->width(); s.height = stateModel->height(); setContentSize(s); ignoreAnchorPointForPosition(false); a.x = float(stateModel->anchorx()) / s.width; a.y = float(stateModel->anchory()) / s.height; setAnchorPoint(a); p.x = 0; p.y = stateModel->heightbyfloor(); for(int j = 0; j < stateModel->animations_size(); j ++) { RTSAnimationModel* animMode = stateModel->mutable_animations(j); BBAnimation* anim = BBAnimation::create(animMode); CCPoint ap = anim->getPosition(); ap.x+=p.x; ap.y+=p.y; anim->setPosition(ap); addChild(anim); } } //添加到单位视觉层 // m_pEntity->getVisualLayer()->addChild(this); };