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

Cocos2d-x3.3Final(2) Layout常用成员函数(C++)

发布时间:2020-12-14 20:13:28 所属栏目:百科 来源:网络整理
导读:Layout* root = static_castLayout*(_uiLayer-getChildByTag(81)) ; //找到根布局 81 Layout* background = static_castLayout*(root-getChildByName("background_Panel")); //其他的组件都可以在这个布局里找,注意看是root-getChildByName Layout* layout

Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81)) ; //找到根布局 81

Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel")); //其他的组件都可以在这个布局里找,注意看是root->getChildByName

Layout* layout = Layout::create(); //创建新布局

layout->setContentSize(Size(280,150)); //设置大小

layout->setPosition(Vec2()) //设置位置

{

layout->setBackGroundColorType(Layout::BackGroundColorType::SOLID); //设置背景颜色类型(固体)

layout->setBackGroundColor(Color3B(128,128,128)); //设置背景颜色

}

{

layout->setBackGroundColorType(Layout::BackGroundColorType::GRADIENT); //设置背景颜色类型(渐变)

layout->setBackGroundColor(Color3B(64,64,64),Color3B(192,192,192));

}

layout->setClippingEnabled(true); //允许剪裁

layout->setBackGroundImage("cocosui/Hello.png"); //设置背景图片

layout->setBackGroundImageScale9Enabled(true); //设置背景图片九宫格可用

layout->setLayoutType(LayoutType::VERTICAL); //设置布局为垂直布局

layout->setLayoutType(LayoutType::HORIZONTAL); //设置布局为水平布局

{ //布局为整齐的行列布局

layout->setLayoutType(LayoutType::RELATIVE);

Button * button_TopLeft = Button::create("cocosui/animationbuttonnormal.png","cocosui/animationbuttonpressed.png");

layout->addChild(button_TopLeft);

RelativeLayoutParameter * rp_TopLeft = RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT);

button_TopLeft->setLayoutParameter(rp_TopLeft);


//依次类推

RelativeLayoutParameter * rp_TopCenter = RelativeLayoutParameter::create();

rp_TopCenter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL);

button_TopCenter->setLayoutParameter(rp_TopCenter);

PARENT_TOP_RIGHT

PARENT_LEFT_CENTER_VERTICAL

CENTER_IN_PARENT

PARENT_RIGHT_CENTER_VERTICAL

PARENT_LEFT_BOTTOM

PARENT_BOTTOM_CENTER_HORIZONTAL

PARENT_RIGHT_BOTTOM

}


{ //一种相对布局

layout->setLayoutType(LayoutType::RELATIVE);

RelativeLayoutParameter * rp_Center = RelativeLayoutParamter::create();

rp_Center->setRelativeName("rp_Center");

rp_Center->setAlign(RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT);

imageView_Center->setLayoutParameter(rp_Center);

//依次类推,但是注意rp_AboveCenter->setRelativeToWidgetName("rp_Center");//依然是rp_Center

参数依次是 LOCATION_ABOVE_CENTER

LOCATION_BELOW_CENTER

LOCATION_LEFT_OF_CENTER

LOCATION_RIGHT_OF_CENTER

}

(编辑:李大同)

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

    推荐文章
      热点阅读