cocos2d-x3.0 相对布局(一)「建议收藏」

cocos2d-x3.0 相对布局(一)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

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 相对布局(一)「建议收藏」

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116721.html原文链接:https://javaforall.net

(0)
上一篇 2022年1月16日 下午9:00
下一篇 2022年1月16日 下午10:00


相关推荐

  • 在node.js中使用COOKIE

    node.js中如何向客户端发送COOKIE呢?有如下两个方案:一、使用response.writeHead,代码示例://设置过期时间为一分钟1vartoday=newDate();

    2021年12月21日
    44
  • java开发webservice的几种方式「建议收藏」

    java开发webservice的几种方式「建议收藏」webservice的应用已经越来越广泛了,下面介绍几种在Java体系中开发webservice的方式,相当于做个记录。1.Axis2方式Axis是apache下一个开源的webservice开发

    2022年7月4日
    30
  • 扫描web漏洞的工具_系统漏洞扫描工具有哪些

    扫描web漏洞的工具_系统漏洞扫描工具有哪些十大Web漏洞扫描工具AcunetixWebVulnerabilityScanner[(简称AwVS)AwVS是一款知名的Web网络漏洞扫描工具,它通过网络爬虫测试你的网站安全,检测流行安全漏洞。a)、自动的客户端脚本分析器,允许对Ajax和Web2.0应用程序进行安全性测试b)、业内最先进且深入的SQL注入和跨站脚本测试c)、高级渗透测试工具,例如HTTPEditor和HTTPFuzzerd)、可视化宏记录器帮助您轻松测试web表格和受密码保护的区域e)、支持含有CAPT

    2025年8月30日
    12
  • T检验三种方法的区分

    T检验三种方法的区分之前的文章中SPSSAU已经给大家详细地介绍了方差分析,之后收到的一些反馈以及日常的答疑中,我们发现关于T检验三种方法的区分还有很多小伙伴搞不清楚,下面就结合着具体案例详细聊聊T检验的那点事。01.概念T检验是通过比较不同数据的均值,研究两组数据之间是否存在显著差异。02.分类不同的T检验方法适用于不同的分析场景,具体的分类如下:03….

    2022年6月19日
    34
  • mysql全文检索 分词_sqlserver全文检索

    mysql全文检索 分词_sqlserver全文检索通常情况下,全文检索引擎我们一般会用ES组件(传送门:SpringBoot系列——ElasticSearch),但不是所有业务都有那么大的数据量、那么大的并发要求,MySQL5.7之后内置了ngram分词器,支持中文分词,使用全文索引,即可实现对中文语义分词检索MySQL全文检索官方文档介绍:https://dev.mysql.com/doc/refman/5.7/en/fulltext-search.html  查看MySQL版本创建game游戏表,并插入数据插入全文索引  可以在mysq

    2022年8月24日
    12
  • 慧荣SM2246XT主控的固态硬盘修复开卡不识别怎么短接方法

    慧荣SM2246XT主控的固态硬盘修复开卡不识别怎么短接方法一块坏了的240G的固态硬盘,电脑完全不认盘了,所以想修复一下,拆开看到主控是慧荣的SM2246XT,幸好此主控是有开卡软件的,下载也比较方便,最新的SM2246XT_MP_EnhancePageMode_MPQ1102A_DBQ0412_FWR1212A.rar修复成功率很高,但跟U盘量产不同,固态硬盘开卡是需要短接的,但很多人不知道SM2246XT的固态硬盘该怎么短接,这里就教大家。如图拆开ssd外壳后可以看到板子上有ROMMODE的字样,那里就是短接的位置了,这里的4个短接点,我们是需要用镊子两两短

    2022年6月14日
    190

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号