cocos2d-x3.0 相对布局(一)
来源:互联网 发布:java工作日报 编辑:程序博客网 时间:2024/05/22 15:38
2dx中的相对布局和Android中的非常类似,如果之前做过Android应该非常容易上手。
Size widgetSize = Director::getInstance()->getWinSize(); Text* alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 ); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f)); addChild(alert); Layout* layout = Layout::create(); layout->setSize(Size(widgetSize.width, widgetSize.height)); //横向排列,这里类似Android里的线性布局 layout->setLayoutType(LAYOUT_RELATIVE); /*以图片为背景*/ layout->setBackGroundImageScale9Enabled(true); layout->setBackGroundImage("green_edit.png"); layout->setPosition(Point(0,0)); addChild(layout); Button* button_TopLeft = Button::create("animationbuttonnormal.png", "animationbuttonpressed.png"); layout->addChild(button_TopLeft); RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create(); rp_TopLeft->setAlign(RELATIVE_ALIGN_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(RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL); button_TopCenter->setLayoutParameter(rp_TopCenter); Button* button_TopRight = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_TopRight); RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create(); rp_TopRight->setAlign(RELATIVE_ALIGN_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(RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL); button_LeftCenter->setLayoutParameter(rp_LeftCenter); //center Button* buttonCenter = Button::create("animationbuttonnormal.png","animationbuttonnormal.png"); layout->addChild(buttonCenter); RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create(); rpCenter->setAlign(RELATIVE_CENTER_IN_PARENT); buttonCenter->setLayoutParameter(rpCenter); Button* button_RightCenter = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_RightCenter); RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create(); rp_RightCenter->setAlign(RELATIVE_ALIGN_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(RELATIVE_ALIGN_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(RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL); button_BottomCenter->setLayoutParameter(rp_BottomCenter); Button* button_RightBottom = Button::create("animationbuttonnormal.png","animationbuttonpressed.png"); layout->addChild(button_RightBottom); RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create(); rp_RightBottom->setAlign(RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM); button_RightBottom->setLayoutParameter(rp_RightBottom);
0 0
- cocos2d-x3.0 相对布局(一)
- Cocos2d-x3.0 RenderTexture(一) 保存
- cocos2d-x3.0 lua学习(一)
- Cocos2d-x3.0 EventListener
- cocos2d-x3.0 SpriteFrameCache
- Cocos2d-x3.0触摸
- Cocos2d-x3.0 Button
- Cocos2d-x3.0 LoadingBar
- cocos2d-x3.0 PageView
- cocos2d-x3.0 RichText
- cocos2d-x3.0 ScrollView
- cocos2d-x3.0 Slider
- cocos2d-x3.0 ListView
- cocos2d-x3.0
- cocos2d-x3.0 柱图
- Cocos2d-x3.0(一)Cocos2d-x3.0简介以及创建新的Cocos2d-x跨平台工程
- 枫叶天空Cocos2d-x3.0系列教程一 环境配置
- xcode 5 cocos2d-x3.0 一 环境搭建
- C++中,如何执行一个控制台命令并返回结果到字符串string中
- jobschu boa、cgi组合利用html到cgi的实现代码
- Valid Parentheses
- codeforce Present from Lena 打印菱形
- Android读写配置文件
- cocos2d-x3.0 相对布局(一)
- java socket 多线程
- CM之过程总览
- maven下载及环境设置备忘
- Hibernate(二)
- 初学Java,枚举类(二十二)
- C#网络编程 异步
- epoll的原理
- configure.ac:20: error: Autoconf version 2.65 or higher is required