Cocos2d-x3.3Final2 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

}

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...