cocos2d-x3.0 相对布局(一)
2dx相对布局和Android非常类似。假设前完成Android它应该是easy入门。
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);
cocos2d-x3.0 相对布局(一)的更多相关文章
- Cocos2D v2.0至v3.x简洁转换指南(三)
Cocos2D 3.3中的注意事项 如果你在使用Cocos2D 3.3+(是SpriteBuilder 1.3+的一部分)你将不得不替分别的换所有存在的UITouch和UITouchEvent为CCT ...
- 如何在Cocos2D 1.0 中掩饰一个精灵(六)
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 掩饰一个精灵:实现代码 打开HelloWorldLayer.m并 ...
- 如何在Cocos2D 1.0 中掩饰一个精灵(一)
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 原帖来自Ray Wunderlich写的精彩的文章 How To ...
- Cocos2D v2.0至v3.x简洁转换指南(二)
触摸处理 我们在稍后将完成Cocos2d 3.0中触摸处理的完整教程.而现在最重要的是知道如何去启用触摸处理在你的CCNode中: self.userInteractionEnabled = TRUE ...
- 如何将各种低版本的discuz版本升级到discuz x3.0
最近在做discuz改版的项目,遇到了很多问题,相信很多拥有discuz论坛的版主,站长和程序猿在升级或改版discuz的过程中遇到过和我一样的问题,所以我开了一个discuz专栏,为大家讲解一下di ...
- cocos2d 2.0和UIKit混合编程, Push CCDirector的时候出现黑屏的天坑
症状 使用cocos2d 2.0和UIKit混合编程, 有一块用cocos2d编写的小程序, 将CCDirector push到一个UINavigationController里面. 虽然事先在后台初 ...
- cocos2d-x3.0创建第一个jsb游戏
第一步: 最新的cocos2d-x.下载地址https://github.com/cocos2d/cocos2d-x github上最新的引擎,值得注意的是官网上发布的引擎是稳定版.选择哪种就看个人喜 ...
- cocos2d(3.0)一些基础的东西
1.创建项目后环境配置: 附加文件夹:加入 $(EngineRoot) $(EngineRoot)cocos $(EngineRoot)cocos\editor-support $(EngineRoo ...
- Visual C++ 8.0对象布局的奥秘:虚函数、多继承、虚拟继承(VC直接输出内存布局)
原文:VC8_Object_Layout_Secret.html 哈哈,从M$ Visual C++ Team的Andy Rich那里又偷学到一招:VC8的隐含编译项/d1reportSingleCl ...
随机推荐
- Cocos2d-x CCProgressTimer
CCProgressTimer,创建使用这个节点可以大致实现两个作用的效果: 其一:在游戏中几乎大部分的游戏启动界面都是游戏加载画面,那么用到的一般是进度条提示加载进度,其使用的就是CCProgres ...
- jquery 拓展方法
摘抄自(http://hi.baidu.com/jjjvzugcpmcdmor/item/0e32a89c36a18544f04215d7) $.fn是指jquery的命名空间,加上fn上的方法及属性 ...
- RT3070 USB WIFI 在连接socket编程过程中问题总结
最近耗时多天,成功的将RT3070驱动.并解决了socket的网络编程,成功的在BA9G10上面实现了USB wif.连上家里的无线路由器,通过ubuntu下面建立的服务端程序,将BA9G10中的数据 ...
- drupal THEME主要文件
**.info 文件** .info 文件是一个必需的文件:Drupal 必须包括它,才干看到主题. .info 文件告诉 Drupal 主题的内部名称.比如,假设这个文件的名称是 ibmtheme. ...
- skynet源代码学习 - 从全局队列中弹出/压入一个消息队列过程
学习云风的skynet源代码,简单记录下. void skynet_globalmq_push(struct message_queue * queue) { struct global_queue ...
- Android 表格布局<TableLayout>
表格布局即,tableLayout,表格布局通过行.列的形式来管理UI组件,TablelLayout并不需要明确地声明包含多少行.多少列,而是通过TableRow,以及其他组件来控制表格的行数和列数, ...
- 14.3.4 Phantom Rows 幻影行
14.3.4 Phantom Rows 幻影行 所谓的幻读为发生在一个事务 当相同的查询产生不同的结果集在不同的时间. 比如,如果一个SELECT被执行2次, 但是第2次返回的记录不是第一次返回的记录 ...
- J2EE 13规范(4)-JSP
JSP全称(Java Server Page ),也称javaserver页面.看到jsp是否立马想到原先以前学过的asp呢. 一.jsp和asp的比較: JSP(Java Server Page)与 ...
- Java Swing界面编程(31)---菜单条:JMenu
package com.beyole.test; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMe ...
- 由“Jasperrpeorts 4.1.2升级到5.1.2对flex项目的解析”到AS3 带命名空间的XML的操作
原文同步至:http://www.waylau.com/from-jasperrpeorts-4-1-2-upgraded-to-5-1-2-parsing-of-flex-projects-to-t ...