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


相关推荐

  • 汉罗塔递归c_递归实现汉诺塔问题

    汉罗塔递归c_递归实现汉诺塔问题递归解决汉罗塔问题

    2022年10月12日
    2
  • navicat激活码mac2022(JetBrains全家桶)2022.03.08「建议收藏」

    (navicat激活码mac2022)JetBrains旗下有多款编译器工具(如:IntelliJ、WebStorm、PyCharm等)在各编程领域几乎都占据了垄断地位。建立在开源IntelliJ平台之上,过去15年以来,JetBrains一直在不断发展和完善这个平台。这个平台可以针对您的开发工作流进行微调并且能够提供…

    2022年4月2日
    160
  • java bitwise_Java Core.bitwise_and方法代码示例

    java bitwise_Java Core.bitwise_and方法代码示例importorg.opencv.core.Core;//导入方法依赖的package包/类publicMatskinDetection(Matsrc){//definetheupperandlowerboundariesoftheHSVpixel//intensitiestobeconsidered’skin’Scalarlower=newSca…

    2025年6月3日
    3
  • Redis 数据类型

    1.String(字符串)string是redis最基本的类型,一个key对应一个valuestring类型是二进制安全的,即它可以包含任何数据setkeyvalue创建一个键值对getkey得到key对应的值示例:redis127.0.0.1:6379>setnamezhangsanOKredis127….

    2022年4月9日
    38
  • Rsyslogd 配置[通俗易懂]

    Rsyslogd 配置[通俗易懂]Rsyslogd配置一般的,Rsyslogd的配置文件在/etc/rsyslog.conf。配置文件格式有3种格式的配置文件basic基础配置格式,兼容syslog.conf格式advanced以前叫RainerScript格式,在rsyslogv6开始使用obsoletelegacy传统的格式,仅为确保旧有配置不会出错需要用哪种格式强烈建议不要使用传统格式,应在基…

    2022年8月15日
    5
  • 框架梳理|企业大数据管理之道「建议收藏」

    框架梳理|企业大数据管理之道「建议收藏」大数据管理——企业转型升级与竞争力重塑之道》一书,从大数据驱动决策、大数据优化管理、大数据智慧营销、大数据发现创新、大数据推动转型、大数据保障安全六个维度全面分析了大数据对传统企业的应用价值,提供可借鉴的案例和深度有格局的思考。本文主要讲述的就是对于这本书的个人看法。

    2022年5月1日
    62

发表回复

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

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