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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 文件句柄数_系统文件句柄

    文件句柄数_系统文件句柄内核参数fs.file-max指定了系统范围内所有进程可打开的文件句柄的数量限制。合理值计算方法:取决于内存,每1M内存可增加100个。默认情况下,不要将超过10%的内存用于文件。将文件句柄数设置太大的危害是,当大量的文件句柄都为sockets时,会占用大量的内存,这些内存都是不可交换的。要记得的是网络套接字连接符也是文件。对于百万级连接数的进程来说,要设置单个进程可打开的文件句柄数为百万个。比如256G内存,应该配置的值为:256*0.1*1024*100=2621440设置方式:vi/et

    2022年10月17日
    1
  • navicat 15.0.17版本激活码_最新在线免费激活

    (navicat 15.0.17版本激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~0…

    2022年3月28日
    155
  • Android下载apk异常java.net.SocketTimeoutException: timeout解决办法

    Android下载apk异常java.net.SocketTimeoutException: timeout解决办法1、问题实现下载apk的时候,抛出下面异常java.net.SocketTimeoutException:timeout2、分析很明显是socket超时了,由于我的wifi网络比较慢,设置的超时时间可能短了。在写入由GetRequestStream方法返回的流时,或在读取由GetResponseStream方法返回的流时,会用到ReadWriteTimeout属性,ReadWrite…

    2022年8月31日
    6
  • A星算法说明「建议收藏」

    A星算法说明「建议收藏」A*算法说明文章目录前言原理说明如何构造h(n)h(n)h(n)一、欧氏距离二、曼哈顿距离三、其他关于g(n)g(n)g(n)路况设置如何实现完整的流程核心代码a_star.ha_star.cppmap_matrix.hmap_matrix.cpp代码使用示例GUI程序下载链接GUI程序使用说明前言  因为最近要写一个毕业设计,有用到自动寻路的功能,因为我要在一个机器里跑算法然后控制机器人自动按照路线到达目的地,所以用Python等解释型语言或Unity等游戏引擎写这个算法都不太合适,我使用的机器要尽

    2022年10月6日
    4
  • sublime txt3 激活码【在线注册码/序列号/破解码】

    sublime txt3 激活码【在线注册码/序列号/破解码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月19日
    36
  • plsql development 注册码

    plsql development 注册码今天使用plsqldeveloper时,突然发现使用不了了,后面发现原来之前的那个都是使用版的,后面网上查阅了相关注册码,找到如下两个可以使用的,记录一下,方便自己,也方便大家。productcode:ke4tv8t5jtxz493kl8s2nn3t6xgngcmgf3serialNumber:264452password:xs374ca或者也可用下面这个productcode:4vkjwhfeh3ufnqnm…

    2022年7月24日
    41

发表回复

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

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