void PubSprite::unseleted() { if (pub_sprite_ == NULL) return; const float kDisplayWidth = 354.0 * gScale; const float kDisplayHeight = 530.0 * gScale; Rect inset_rect = CCRectMake(11, 13, 1, 1); Rect full_rect = CCRectMake(0, 0, 22, 23); pub_sprite_->removeAllChildren(); /* add the cloud state */ Sprite *cloud = Sprite::create("main_screen/cloud_unselected.png"); const float kCloudOffsetY = 317; if (gScale == 1.0) cloud->setPosition(ccp(kDisplayWidth*2/3, kDisplayHeight*2/3+kCloudOffsetY)); else cloud->setPosition(ccp(kDisplayWidth, kDisplayHeight+kCloudOffsetY)); cloud->setTag(1); pub_sprite_->addChild(cloud, 1); /* add the white border*/ const float kBorderWidth = 460; const float kBorderHeight = 685; const float kBorderX = 226; const float kBorderY = 336; Scale9Sprite *wborder = Scale9Sprite::create("main_screen/border_unselected.png", full_rect, inset_rect); wborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight)); wborder->setPosition(ccp(kBorderX, kBorderY)); wborder->setTag(1); pub_sprite_->addChild(wborder); }
EditBox * TDDHelper::createEditBox(Node *parent, Point position, Size size) { Scale9Sprite *bg = Scale9Sprite::create(); // empty sprite 9 bg->addChild(LayerColor::create(Color4B::WHITE, size.width, size.height)); // Add the background layer Point layerPos = Point(position); layerPos.x -= size.width / 2; layerPos.y -= size.height / 2; float scale = getBestScale(); // Add the Edit box EditBox *edit = EditBox::create(size, bg); edit->setPosition(position); edit->setFont(TDD_FONT_NAME, (int)(scale * TDD_EDITBOX_FONT_SIZE)); edit->setFontColor(TDD_EDITBOX_TEXT_COLOR); if(parent != NULL) { parent->addChild(edit); } return edit; }
TableViewCell* SkillTableView::tableCellAtIndex(TableView *table, ssize_t idx) { CCString* str = CCString::createWithFormat("ui/skill/skill_%d.png",2001 + (int)idx); TableViewCell* cell = table->dequeueCell(); if (!cell) { cell = new TableViewCell(); cell->autorelease(); Scale9Sprite* bg = Scale9Sprite::create("ui/cell.png"); bg->setAnchorPoint(Point::ZERO); bg->setPosition(Point::ZERO); bg->setPreferredSize(Size(420, 80)); cell->addChild(bg); Sprite* skill = Sprite::create(str->getCString()); skill->setPosition(Point(50, 40)); cell->addChild(skill, 0, 123); m_skillVec.push_back(skill); } else { Sprite* skill = (Sprite*)cell->getChildByTag(123); Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(str->getCString()); skill->setTexture(texture); } cell->setTag(2001+(int)idx); return cell; }
void PubSprite::semiselected() { if (pub_sprite_ == NULL) return; const float kDisplayWidth = 354.0 * gScale; const float kDisplayHeight = 530.0 * gScale; Rect inset_rect = CCRectMake(38, 29, 1, 1); Rect full_rect = CCRectMake(0, 0, 74, 284); pub_sprite_->removeAllChildren(); /* add the sun state */ Sprite *sun = Sprite::create("main_screen/sun_semi.png"); const float kSunOffsetY = 317; if (gScale == 1.0) sun->setPosition(ccp(kDisplayWidth*2/3, kDisplayHeight*2/3+kSunOffsetY)); else sun->setPosition(ccp(kDisplayWidth, kDisplayHeight+kSunOffsetY)); sun->setTag(2); pub_sprite_->addChild(sun, 1); /* add the white border*/ const float kBorderWidth = 480; const float kBorderHeight = 706; const float kBorderX = 226; const float kBorderY = 336; Scale9Sprite *yborder = Scale9Sprite::create("main_screen/border_selected.png", full_rect, inset_rect); yborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight)); yborder->setPosition(ccp(kBorderX, kBorderY)); yborder->setTag(2); pub_sprite_->addChild(yborder); }
bool ArmsBackGroud::init(){ audioEffect *audioEffectTemp = nullptr; audioEffectTemp->myPlaneChoose(); Scale9Sprite *background = Scale9Sprite::createWithSpriteFrameName("ArmsBackground.png"); background->setAnchorPoint(Point(0, 0)); this->addChild(background); MenuItemSprite* ButtonReturnItem = MenuItemSprite::create(Sprite::createWithSpriteFrameName("arrow_right.png"), Sprite::createWithSpriteFrameName("arrow_right.png"), CC_CALLBACK_1(ArmsBackGroud::ButtonReturn, this)); Menu* ButtonReturn = Menu::create(ButtonReturnItem, nullptr); //ButtonReturn->setScale(0.2f); ButtonReturn->setAnchorPoint(Point(0, 0)); ButtonReturn->setPosition(30,450); this->addChild(ButtonReturn); MenuItemSprite* myplane1item = MenuItemSprite::create(Sprite::createWithSpriteFrameName("plane1Show.png"), Sprite::createWithSpriteFrameName("plane1Show.png"), CC_CALLBACK_1(ArmsBackGroud::myPlaneSelect1, this)); Menu* myPlane1 = Menu::create(myplane1item, nullptr); myPlane1->setScale(0.5f); myPlane1->setAnchorPoint(Point(0, 0)); myPlane1->setPosition(50, 380); this->addChild(myPlane1); Sprite* myPlane1Atr = Sprite::createWithSpriteFrameName("myPlane1atr.png"); myPlane1Atr->setAnchorPoint(Point(0.5, 0.5)); myPlane1Atr->setScale(0.4); myPlane1Atr->setPosition(200, 380); this->addChild(myPlane1Atr); MenuItemSprite* myplane2item = MenuItemSprite::create(Sprite::createWithSpriteFrameName("plane2Show.png"), Sprite::createWithSpriteFrameName("plane2Show.png"), CC_CALLBACK_1(ArmsBackGroud::myPlaneSelect2, this)); Menu* myPlane2 = Menu::create(myplane2item, nullptr); myPlane2->setScale(0.5f); myPlane2->setAnchorPoint(Point(0, 0)); myPlane2->setPosition(50, 230); this->addChild(myPlane2); Sprite* myPlane2Atr = Sprite::createWithSpriteFrameName("myPlane2atr.png"); myPlane2Atr->setAnchorPoint(Point(0.5, 0.5)); myPlane2Atr->setScale(0.4); myPlane2Atr->setPosition(200, 230); this->addChild(myPlane2Atr); MenuItemSprite* myplane3item = MenuItemSprite::create(Sprite::createWithSpriteFrameName("plane3Show.png"), Sprite::createWithSpriteFrameName("plane3Show.png"), CC_CALLBACK_1(ArmsBackGroud::myPlaneSelect3, this)); Menu* myPlane3 = Menu::create(myplane3item, nullptr); myPlane3->setScale(0.5f); myPlane3->setAnchorPoint(Point(0, 0)); myPlane3->setPosition(50, 80); this->addChild(myPlane3); Sprite* myPlane3Atr = Sprite::createWithSpriteFrameName("myPlane3atr.png"); myPlane3Atr->setAnchorPoint(Point(0.5, 0.5)); myPlane3Atr->setScale(0.4); myPlane3Atr->setPosition(200, 80); this->addChild(myPlane3Atr); return true; }
void DialogLayer::onEnter() { Layer::onEnter(); Size winSize = Director::getInstance()->getWinSize(); Point pCenter = Point(winSize.width / 2, winSize.height / 2); Size contentSize; // 设定好参数,在运行时加载 if (getContentSize().equals(Size::ZERO)) { getSpriteBackGround()->setPosition(winSize.width / 2, winSize.height / 2); this->addChild(getSpriteBackGround(), 0, 0); contentSize = getSpriteBackGround()->getTexture()->getContentSize(); } else { Scale9Sprite *background = getSprite9BackGround(); background->setContentSize(getContentSize()); background->setPosition(winSize.width / 2, winSize.height / 2); this->addChild(background, 0, 0); contentSize = getContentSize(); } // 添加按钮,并设置其位置 this->addChild(getMenuButton()); float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1); Vector<Node*> vecArray = getMenuButton()->getChildren(); Ref* pObj = NULL; int i = 0; for(auto& e : vecArray){ Node* node = dynamic_cast<Node*>(e); node->setPosition(Point(winSize.width/2 - contentSize.width/2+btnWidth*(i+1),winSize.height/2-contentSize.height/3)); i++; } // 显示对话框标题 if (getLabelTitle()){ getLabelTitle()->setPosition(pCenter + Vec2(0, contentSize.height / 2 - 30.0f)); this->addChild(getLabelTitle()); } // 显示文本内容 if (getLabelContentText()){ LabelTTF* ltf = getLabelContentText(); ltf->setPosition(winSize.width / 2, winSize.height / 2 + 20); //ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop)); ltf->setHorizontalAlignment(kCCTextAlignmentLeft); this->addChild(ltf); } // 弹出效果 Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0), ScaleTo::create(0.06, 1.05), ScaleTo::create(0.08, 0.95), ScaleTo::create(0.08, 1.0), NULL); this->runAction(popupLayer); }
Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); if ( pReturn && pReturn->initWithSpriteFrame(spriteFrame, capInsets) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return NULL; }
Scale9Sprite* Scale9Sprite::create(const std::string& file) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithFile(file) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return NULL; }
Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const std::string& file) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); if ( pReturn && pReturn->initWithFile(capInsets, file) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return NULL; }
Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithFile(file, rect) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return nullptr; }
Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithSpriteFrame(spriteFrame) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return NULL; }
Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName, capInsets) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return NULL; }
Scale9Sprite* Scale9Sprite::resizableSpriteWithCapInsets(const Rect& capInsets) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithBatchNode(_scale9Image, _spriteRect, capInsets) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return NULL; }
void PubSprite::selected() { if (pub_sprite_ == NULL) return; const float kDisplayWidth = 354.0 * gScale; const float kDisplayHeight = 530.0 * gScale; Rect inset_rect = CCRectMake(38, 29, 1, 1); Rect full_rect = CCRectMake(0, 0, 74, 284); pub_sprite_->removeAllChildren(); /** * add the sun state */ Sprite *sun = Sprite::create("main_screen/sun_selected.png"); /* gScale is 1 means 1080p, so 2/3 is a fixed number to get the right position */ const float kSunOffsetY = 317; if (gScale == 1.0) sun->setPosition(ccp(kDisplayWidth*2/3, kDisplayHeight*2/3+kSunOffsetY)); else sun->setPosition(ccp(kDisplayWidth, kDisplayHeight+kSunOffsetY)); sun->setTag(2); pub_sprite_->addChild(sun, 1); /** * add the white border */ const float kBorderWidth = 480; const float kBorderHeight = 706; const float kBorderX = 226; const float kBorderY = 336; Scale9Sprite *yborder = Scale9Sprite::create("main_screen/border_selected.png", full_rect, inset_rect); yborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight)); yborder->setPosition(ccp(kBorderX, kBorderY)); yborder->setTag(2); pub_sprite_->addChild(yborder); if (pub_title_ != NULL){ int size = 36; if (strlen(pub_title_) > 35){ size = 32; } LabelTTF *title= LabelTTF::create(pub_title_, "Arial", size); CCLog("title %s, length %d", pub_title_, strlen(pub_title_)); title->setFontFillColor(ccc3(255, 255, 0)); pub_sprite_->addChild(title); const float kTitleOffsetX = 10; const float kTitleOffsetY = 60; if (gScale == 1.0) title->setPosition(kDisplayWidth*2/3-kTitleOffsetX, kTitleOffsetY); else title->setPosition(kDisplayWidth-kTitleOffsetX, kTitleOffsetY); } }
Scale9Sprite* Scale9Sprite::create() { Scale9Sprite *pReturn = new Scale9Sprite(); if (pReturn && pReturn->init()) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return NULL; }
Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets) { Scale9Sprite* ret = new (std::nothrow) Scale9Sprite(); if (ret && ret->initWithSpriteFrame(spriteFrame, capInsets)) { ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); return nullptr; }
Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const std::string& file) { Scale9Sprite* ret = new (std::nothrow) Scale9Sprite(); if (ret && ret->initWithFile(capInsets, file)) { ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); return nullptr; }
Scale9Sprite* Scale9Sprite::create() { Scale9Sprite *ret = new (std::nothrow) Scale9Sprite(); if (ret && ret->init()) { ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); return nullptr; }
Scale9Sprite* Scale9Sprite::resizableSpriteWithCapInsets(const Rect& capInsets) const { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); if ( pReturn && pReturn->init(_scale9Image, _spriteRect, _spriteFrameRotated, _offset, _originalSize, _capInsets) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); return NULL; }
Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName) { Scale9Sprite* ret = new (std::nothrow) Scale9Sprite(); if (ret && ret->initWithSpriteFrameName(spriteFrameName, Rect::ZERO)) { ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); log("Could not allocate Scale9Sprite()"); return nullptr; }
Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName) { Scale9Sprite* pReturn = new Scale9Sprite(); if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName) ) { pReturn->autorelease(); return pReturn; } CC_SAFE_DELETE(pReturn); log("Could not allocate Scale9Sprite()"); return NULL; }
void PubSprite::showpubUnselect() { pub_sprite_->removeAllChildren(); const float kDisplayWidth = 290.0 * gScale; const float kDisplayHeight = 544.0 * gScale; Rect inset_rect = CCRectMake(12, 12, 1, 1); Rect full_rect = CCRectMake(0, 0, 23, 73); /* add the cloud state */ Sprite *cloud = Sprite::create("main_screen/cloud_unselected.png"); const float kCloudOffsetY = 295; const float kCloudOffsetX = 55; if (gScale == 1.0) cloud->setPosition(ccp(kDisplayWidth*2/3+kCloudOffsetX, kDisplayHeight*2/3+kCloudOffsetY)); else cloud->setPosition(ccp(kDisplayWidth+kCloudOffsetX, kDisplayHeight+kCloudOffsetY)); cloud->setTag(1); pub_sprite_->addChild(cloud, 1); /** * add the white border */ const float kBorderWidth = 460; const float kBorderHeight = 730; const float kBorderX = 225; const float kBorderY = 310; Scale9Sprite *wborder = Scale9Sprite::create("showlist/border_unselected.png", full_rect, inset_rect); wborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight)); wborder->setPosition(ccp(kBorderX, kBorderY)); wborder->setTag(2); pub_sprite_->addChild(wborder); if (pub_title_ != NULL){ int size = 36; if (strlen(pub_title_) > 30){ size = 32; } LabelTTF *title= LabelTTF::create(pub_title_, "Arial", size); /** the color is blue */ title->setFontFillColor(ccc3(67, 155, 203)); pub_sprite_->addChild(title); const float kTitleOffsetX = 20; const float kTitleOffsetY = 20; if (gScale == 1.0) title->setPosition(kDisplayWidth*2/3+kTitleOffsetX, -kTitleOffsetY); else title->setPosition(kDisplayWidth+kTitleOffsetX, -kTitleOffsetY); } }
void ControlButton::setPreferredSize(Size size) { if(size.width == 0 && size.height == 0) { _doesAdjustBackgroundImage = true; } else { _doesAdjustBackgroundImage = false; DictElement * item = NULL; CCDICT_FOREACH(_backgroundSpriteDispatchTable, item) { Scale9Sprite* sprite = static_cast<Scale9Sprite*>(item->getObject()); sprite->setPreferredSize(size); } }
Scale9Sprite* Scale9Sprite::resizableSpriteWithCapInsets(const Rect& capInsets) const { // FIXME: there are no test cases for this method Scale9Sprite* ret = new (std::nothrow) Scale9Sprite(); if (ret && ret->init(const_cast<Scale9Sprite*>(this), _rect, _rectRotated, Vec2::ZERO, _originalContentSize, capInsets) ) { ret->autorelease(); return ret; } CC_SAFE_DELETE(ret); return nullptr; }
void PubSprite::showpubSelect() { pub_sprite_->removeAllChildren(); const float kDisplayWidth = 290.0 * gScale; const float kDisplayHeight = 544.0 * gScale; Sprite *sun = Sprite::create("main_screen/sun_semi.png"); const float kSunOffsetY = 315; const float kSunOffsetX = 35; if (gScale == 1.0) sun->setPosition(ccp(kDisplayWidth*2/3+kSunOffsetX, kDisplayHeight*2/3+kSunOffsetY)); else sun->setPosition(ccp(kDisplayWidth+kSunOffsetX, kDisplayHeight+kSunOffsetY)); sun->setTag(2); pub_sprite_->addChild(sun, 1); Rect inset_rect = CCRectMake(30, 27, 1, 1); Rect full_rect = CCRectMake(0, 0, 60, 120); const float kBorderWidth = 500; const float kBorderHeight = 775; const float kBorderX = 225; const float kBorderY = 298; Scale9Sprite *yborder = Scale9Sprite::create("showlist/border_selected.png", full_rect, inset_rect); yborder->setPreferredSize(CCSizeMake(kBorderWidth, kBorderHeight)); yborder->setPosition(ccp(kBorderX, kBorderY)); yborder->setTag(2); pub_sprite_->addChild(yborder); if (pub_title_ != NULL){ int size = 46; if (strlen(pub_title_) > 38){ size = 32; } LabelTTF *title= LabelTTF::create(pub_title_, "Arial", size); /** the color is blue */ title->setFontFillColor(ccc3(67, 155, 203)); pub_sprite_->addChild(title); const float kTitleOffsetX = 20; const float kTitleOffsetY = 30; if (gScale == 1.0) title->setPosition(kDisplayWidth*2/3+kTitleOffsetX, -kTitleOffsetY); else title->setPosition(kDisplayWidth+kTitleOffsetX, -kTitleOffsetY); } }
ControlButton * createBtn(float x, float y, const char * normalBg, const char * pressBg, Ref* target, Control::Handler action) { Scale9Sprite * spNormalBg = createDotaScale9Sprite(normalBg); Scale9Sprite * spPressBg = createDotaScale9Sprite(pressBg); ControlButton *btn = ControlButton::create(spNormalBg); if (spPressBg) btn->setBackgroundSpriteForState(spPressBg, Control::State::HIGH_LIGHTED); btn->setAnchorPoint(Vec2(0, 0)); btn->setPosition(x, y); btn->setZoomOnTouchDown(false); btn->setPreferredSize(spNormalBg->getOriginalSize()); if (target && action) btn->addTargetWithActionForControlEvents(target, action, Control::EventType::TOUCH_UP_INSIDE); return btn; }
void SliderLoader::onDone(cocos2d::Node * pNode, cocos2d::Node * pParent, CCBReader * ccbReader) { Scale9Sprite* background = Scale9Sprite::createWithSpriteFrame(this->_backgroundSprite); background->setContentSize(_contentSize); Sprite* progressSprite = Sprite::create(); progressSprite->setContentSize(_contentSize); progressSprite->addChild(background); background->setAnchorPoint(Point(0.0, 0.5)); Sprite* sprite = Sprite::create(); sprite->setContentSize(_contentSize); sprite->setAnchorPoint(Point(0.0, 0.0)); ((ControlSlider*)pNode)->setContentSize(_contentSize); if (_selectedHandleSprite) ((ControlSlider *)pNode)->initWithSprites(sprite, progressSprite, Sprite::createWithSpriteFrame(this->_handleSprite), Sprite::createWithSpriteFrame(this->_selectedHandleSprite)); else ((ControlSlider *)pNode)->initWithSprites(sprite, progressSprite, Sprite::createWithSpriteFrame(this->_handleSprite)); ((ControlSlider*)pNode)->setAnchorPoint(Point(0.0, 0.25)); _backgroundSprite->release(); _handleSprite->release(); if (_selectedHandleSprite) _selectedHandleSprite->release(); // ((ControlSlider *)pNode)->setMaximumValue(100); // ((ControlSlider *)pNode)->setMinimumValue(0); }
void PopupLayer::onEnter(){ LayerColor::onEnter(); Size winSize = CCDirector::getInstance()->getWinSize(); Point pCenter = Point(winSize.width / 2, winSize.height / 2); // Size contentSize ; // 设定好参数,在运行时加载 //如果没有设置 ContentSize ,那么采取的方案是,窗口大小与传入图片一样大 // if (getContentSize().equals(this->getParent()->getContentSize())) { // getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2)); // this->addChild(getSpriteBackGround(), 0, 0); // contentSize = getSpriteBackGround()->getTexture()->getContentSize(); // } else { // Scale9Sprite *background = getSprite9BackGround(); // background->setContentSize(getContentSize()); // background->setPosition(ccp(winSize.width / 2, winSize.height / 2)); // this->addChild(background, 0, 0); // contentSize = getContentSize(); // } //添加背景图片 Scale9Sprite *background = getSprite9BackGround(); background->setContentSize(m_dialogContentSize); background->setPosition(Point(winSize.width / 2, winSize.height / 2)); this->addChild(background,0,0); // 弹出效果 Action* popupLayer = Sequence::create( ScaleTo::create(0.0, 0.0), ScaleTo::create(0.2, 1.05), ScaleTo::create(0.2, 0.95), ScaleTo::create(0.1, 1.0), CallFunc::create(CC_CALLBACK_0(PopupLayer::backgroundFinish,this)), NULL ); background->runAction(popupLayer); }
void PopLayer::onEnter() { Layer::onEnter(); Size winSize = Director::getInstance()->getVisibleSize(); Vec2 pCenter(winSize.width / 2, winSize.height / 2); Size contentSize; // 设定好参数,在运行时加载 if (getContentSize().equals(Size::ZERO)) { getSpriteBackGround()->setPosition(Vec2(winSize.width / 2, winSize.height / 2)); this->addChild(getSpriteBackGround(), 0, 0); contentSize = getSpriteBackGround()->getTexture()->getContentSize(); } else { Scale9Sprite *background = getSprite9BackGround(); background->setContentSize(getContentSize()); background->setPosition(Vec2(winSize.width / 2, winSize.height / 2)); this->addChild(background, 0, 0); contentSize = getContentSize(); } // 添加按钮,并设置其位置 this->addChild(getMenuButton()); float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1); Vector<Node *> array = getMenuButton()->getChildren(); getMenuButton()->alignItemsHorizontallyWithPadding(50); getMenuButton()->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - contentSize.height / 3)); // int i = 0; // for(auto &bt: array) // { // Node* node = dynamic_cast<Node*>(bt); // node->setPosition(Vec2( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3)); // i++; // } // 显示对话框标题 if (getLabelTitle()){ getLabelTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 35.0f))); this->addChild(getLabelTitle()); } if(getImgTitle()) { getImgTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 40.0f))); this->addChild(getImgTitle()); } // 显示文本内容 if (getLabelContentText()){ LabelTTF* ltf = getLabelContentText(); //ltf->setPosition(Vec2(winSize.width / 2, winSize.height / 2)); ltf->setPosition(pCenter); ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop)); ltf->setHorizontalAlignment(TextHAlignment::LEFT); this->addChild(ltf); } // 弹出效果 Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0), ScaleTo::create(0.06, 1.05), ScaleTo::create(0.08, 0.95), ScaleTo::create(0.08, 1.0), NULL); this->runAction(popupLayer); }
bool SelectBackgroundLayer::init() { auto listenerkeyPad = EventListenerKeyboard::create(); listenerkeyPad->onKeyReleased = CC_CALLBACK_2(SelectBackgroundLayer::onKeyReleased, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerkeyPad, this); //╪сть╠Ё╬╟м╪ Scale9Sprite *background = Scale9Sprite::createWithSpriteFrameName("selectSceneBackground.jpg"); background->setContentSize(Size(Director::getInstance()->getWinSize().width, Director::getInstance()->getWinSize().height)); background->setAnchorPoint(Point(0, 0)); this->addChild(background); Sprite* bottomOfLevel1 = Sprite::createWithSpriteFrameName("bottomOfpicture.png"); bottomOfLevel1->setAnchorPoint(Point(0, 0.5)); bottomOfLevel1->setScale(1.1); //bottomOfLevel->setRotation(90); bottomOfLevel1->setPosition(70, 360); bottomOfLevel1->setOpacity(140); this->addChild(bottomOfLevel1); Sprite* blueBottom1 = Sprite::createWithSpriteFrameName("bottomOfpic.png"); blueBottom1->setAnchorPoint(Point(0, 0.5)); blueBottom1->setScale(0.65); //bottomOfLevel->setRotation(90); blueBottom1->setPosition(75, 295); this->addChild(blueBottom1); Sprite* bottomOfLevel2 = Sprite::createWithSpriteFrameName("bottomOfpicture.png"); bottomOfLevel2->setAnchorPoint(Point(0, 0.5)); bottomOfLevel2->setScale(1.1); //bottomOfLevel->setRotation(90); bottomOfLevel2->setPosition(70,220); bottomOfLevel2->setOpacity(140); this->addChild(bottomOfLevel2); Sprite* blueBottom2 = Sprite::createWithSpriteFrameName("bottomOfpic.png"); blueBottom2->setAnchorPoint(Point(0, 0.5)); blueBottom2->setScale(0.65); //bottomOfLevel->setRotation(90); blueBottom2->setPosition(75, 155); this->addChild(blueBottom2); Sprite* bottomOfLevel3 = Sprite::createWithSpriteFrameName("bottomOfpicture.png"); bottomOfLevel3->setAnchorPoint(Point(0, 0.5)); bottomOfLevel3->setScale(1.1); bottomOfLevel3->setPosition(70, 80); bottomOfLevel3->setOpacity(140); this->addChild(bottomOfLevel3); Sprite* blueBottom3 = Sprite::createWithSpriteFrameName("bottomOfpic.png"); blueBottom3->setAnchorPoint(Point(0, 0.5)); blueBottom3->setScale(0.65); blueBottom3->setPosition(75, 15); this->addChild(blueBottom3); MenuItemSprite* blank1 = MenuItemSprite::create(Sprite::createWithSpriteFrameName("img_bg_1.jpg"), Sprite::createWithSpriteFrameName("img_bg_1.jpg"), CC_CALLBACK_1(SelectBackgroundLayer::selectCheckPoint_1, this)); Menu* menuBlank1 = Menu::create(blank1, nullptr); menuBlank1->setScale(0.15f); menuBlank1->setAnchorPoint(Point(0, 0)); menuBlank1->setPosition(120, 365);//100 this->addChild(menuBlank1); MenuItemSprite* blank2 = MenuItemSprite::create(Sprite::createWithSpriteFrameName("img_bg_2.jpg"), Sprite::createWithSpriteFrameName("img_bg_2.jpg"), CC_CALLBACK_1(SelectBackgroundLayer::selectCheckPoint_2, this)); Menu* menuBlank2 = Menu::create(blank2, nullptr); menuBlank2->setScale(0.15f); menuBlank2->setAnchorPoint(Point(0, 0)); menuBlank2->setPosition(195, 365); this->addChild(menuBlank2); MenuItemSprite* blank3 = MenuItemSprite::create(Sprite::createWithSpriteFrameName("img_bg_3.jpg"), Sprite::createWithSpriteFrameName("img_bg_3.jpg"), CC_CALLBACK_1(SelectBackgroundLayer::selectCheckPoint_3, this)); Menu* menuBlank3 = Menu::create(blank3, nullptr); menuBlank3->setScale(0.15f); menuBlank3->setAnchorPoint(Point(0, 0)); menuBlank3->setPosition(270, 365); this->addChild(menuBlank3); MenuItemSprite* blank4 = MenuItemSprite::create(Sprite::createWithSpriteFrameName("img_bg_4.jpg"), Sprite::createWithSpriteFrameName("img_bg_4.jpg"), CC_CALLBACK_1(SelectBackgroundLayer::selectCheckPoint_4, this)); Menu* menuBlank4 = Menu::create(blank4, nullptr); menuBlank4->setScale(0.15f); menuBlank4->setAnchorPoint(Point(0, 0)); menuBlank4->setPosition(195, 225);//590 this->addChild(menuBlank4); MenuItemSprite* blank5 = MenuItemSprite::create(Sprite::createWithSpriteFrameName("img_bg_5.jpg"), Sprite::createWithSpriteFrameName("img_bg_5.jpg"), CC_CALLBACK_1(SelectBackgroundLayer::selectCheckPoint_5, this)); Menu* menuBlank5 = Menu::create(blank5, nullptr); menuBlank5->setScale(0.15f); menuBlank5->setAnchorPoint(Point(0, 0)); menuBlank5->setPosition(195, 85);//590 this->addChild(menuBlank5); // Sprite* blank2 = Sprite::createWithSpriteFrameName("img_bg_2.jpg"); // blank2->setScale(0.3); // blank2->setPosition(365, 590); // this->addChild(blank2); // Sprite* blank2_locked = Sprite::createWithSpriteFrameName("locked.png"); // blank2_locked->setPosition(365, 590); // this->addChild(blank2_locked); // // Sprite* blank3 = Sprite::createWithSpriteFrameName("img_bg_3.jpg"); // blank3->setScale(0.3); // blank3->setPosition(565, 590); // this->addChild(blank3); // Sprite* blank3_locked = Sprite::createWithSpriteFrameName("locked.png"); // blank3_locked->setPosition(565, 590); // this->addChild(blank3_locked); // Sprite* blank4 = Sprite::createWithSpriteFrameName("img_bg_4.jpg"); // blank4->setScale(0.3); // blank4->setPosition(165, 390); // this->addChild(blank4); // Sprite* blank4_locked = Sprite::createWithSpriteFrameName("locked.png"); // blank4_locked->setPosition(165, 390); // this->addChild(blank4_locked); // // Sprite* blank5 = Sprite::createWithSpriteFrameName("img_bg_5.jpg"); // blank5->setScale(0.3); // blank5->setPosition(365, 390); // this->addChild(blank5); // Sprite* blank5_locked = Sprite::createWithSpriteFrameName("locked.png"); // blank5_locked->setPosition(365, 390); // this->addChild(blank5_locked); // // Sprite* blank6 = Sprite::createWithSpriteFrameName("blank.png"); // blank6->setPosition(565, 390); // blank6->setScale(0.6); // this->addChild(blank6); // Sprite* blank6_locked = Sprite::createWithSpriteFrameName("locked.png"); // blank6_locked->setPosition(565, 390); // this->addChild(blank6_locked); // TTFConfig ttfConfig("fonts/SIMLI.TTF", 50); // // Label* titleLabel = Label::createWithTTF(ttfConfig, "ChoseCheckPoint", TextHAlignment::CENTER); // titleLabel->enableShadow(); // titleLabel->setColor(Color3B(255, 201, 37)); // titleLabel->setPosition(Director::getInstance()->getWinSize().width / 2, Director::getInstance()->getWinSize().height - 250); // this->addChild(titleLabel); return true; }