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

前端之家收集整理的这篇文章主要介绍了Cocos2d-x3.3Final(2) Layout常用成员函数(C++)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

}

原文链接:/cocos2dx/344651.html

猜你在找的Cocos2d-x相关文章