加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Cocos2d-x Layout使用三

发布时间:2020-12-14 16:54:36 所属栏目:百科 来源:网络整理
导读:Layout* layout = Layout::create(); layout-setLayoutType( LayoutType::RELATIVE ); layout-setContentSize(Size(600,550)); layout- setAnchorPoint(Point(0.5f,0.5f)); layout-setBackGroundColorType(Layout::BackGroundColorType::SOLID); layout-setBa
Layout* layout = Layout::create();
layout->setLayoutType( LayoutType::RELATIVE);
layout->setContentSize(Size(600,550));
layout-> setAnchorPoint(Point(0.5f,0.5f));
layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
layout->setBackGroundColor(Color3B::GREEN);
Size size = Director::getInstance()->getVisibleSize();
layout->setPosition(Vec2(size.width / 2.0f,size.height / 2));
this->addChild(layout);

// top left
Button* button_TopLeft = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");
layout->addChild(button_TopLeft);

RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create();
rp_TopLeft-> setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT);
button_TopLeft-> setLayoutParameter(rp_TopLeft); // top center horizontal Button* button_TopCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_TopCenter); RelativeLayoutParameter* rp_TopCenter = RelativeLayoutParameter::create(); rp_TopCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL); button_TopCenter->setLayoutParameter(rp_TopCenter); // top right Button* button_TopRight = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_TopRight); RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create(); rp_TopRight->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT); button_TopRight->setLayoutParameter(rp_TopRight); // left center Button* button_LeftCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_LeftCenter); RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create(); rp_LeftCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL); button_LeftCenter->setLayoutParameter(rp_LeftCenter); // center Button* buttonCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(buttonCenter); RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create(); rpCenter->setAlign(RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT); buttonCenter->setLayoutParameter(rpCenter); // right center Button* button_RightCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_RightCenter); RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create(); rp_RightCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_CENTER_VERTICAL); button_RightCenter->setLayoutParameter(rp_RightCenter); // left bottom Button* button_LeftBottom = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_LeftBottom); RelativeLayoutParameter* rp_LeftBottom = RelativeLayoutParameter::create(); rp_LeftBottom->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM); button_LeftBottom->setLayoutParameter(rp_LeftBottom); // bottom center Button* button_BottomCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_BottomCenter); RelativeLayoutParameter* rp_BottomCenter = RelativeLayoutParameter::create(); rp_BottomCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL); button_BottomCenter->setLayoutParameter(rp_BottomCenter); // right bottom Button* button_RightBottom = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_RightBottom); RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create(); rp_RightBottom->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_BOTTOM); button_RightBottom->setLayoutParameter(rp_RightBottom);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读