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 ...
随机推荐
- 如何在github中贡献自己的力量
如何参与github的开源项目? 1.找一个发出“pull requests”的项目.有以下几个方法:最简单的方式是,读项目的readme文件.它会告诉你,项目的拥有者是否急切的需要协助.如果read ...
- [置顶] 关于redhat系统yum源的配置2
(二)配置yum源(官方) 1.在终端输入以下命令(RHEL6/CentOS6) wget http://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/ ...
- camel-name-utils 在驼峰风格跟下划线风格之间切换
用处 用来将字符串在驼峰风格跟下划线风格之间切换. 对于一般人可能没用.对于写orm框架的人有点作用. 样例: company_name -> companyName 安装方式 加入下面依赖到p ...
- [iOS]简单的APP引导页的实现 (Swift)
在第一次打开APP或者APP更新后通常用引导页来展示产品特性 我们用NSUserDefaults类来判断程序是不是第一次启动或是否更新,在AppDelegate.swift中加入以下代码: func ...
- Cocos2d-x 创建(create)动画对象CCAnimation报错分析
本人在使用精灵表单创建动画的过程中突然遇到了一些个问题,下面进行一下分析总结. 根据在Cocos2d-iphone中的经验,我写出了如下的代码: CCSpriteFrameCache::sharedS ...
- Memcahce(MC)系列(一)Memcache介绍、使用、存储、算法、优化
写在前面:前不久在工作中被问到关于MC一致哈希的问题,由于时隔太久差点儿忘记,特前来恶补一下MC,下面是前几年在工作中学习MC时的一些资料,来历不明,特整理一下,希望对大家的学习也能有帮助. 32 的 ...
- 拆分字符串,GetHtmlByWebBrowser,UnicodeToMBCS,提升进程权限
1. // 根据字符串,拆分字符串,相当于vb中的split函数 function SplitString(const Source, ch: string): TStringList; var te ...
- java学习笔记12--国际化
java学习笔记12--国际化 国际化的操作就是指一个程序可以同时适应多门语言,即:如果现在程序者是中国人,则会以中文为显示文字,如果现在程序的使用者是英国人,则会以英语为显示的文字,也就是说可以通过 ...
- Windows8和MacOS10.9双系统安装及Mac经常使用软件安装--联想E49A
前提 本篇内容所描写叙述的内容仅仅适合联想E49A笔记本,经过本篇的内容之后,对于Mac OS 10.9的使用达到正常工作使用的标准,完美度已经比較好了. 结果例如以下:显卡.网卡(RTL8168). ...
- Appium介绍
Appium介绍 Appium是一个移动端的自动化框架,可用于测试原生应用,移动网页应用和混合型应用,且是跨平台的.可用于IOS和Android以及firefox的操作系统.原生的应用是指用andro ...