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


相关推荐

  • 一般人都不知道的功能强大的超级搜索引擎!!!!「建议收藏」

    一般人都不知道的功能强大的超级搜索引擎!!!!「建议收藏」百度的中文搜索非常的好。Google的搜索引擎支持非常多种语言。速度也非常快,据说有8000多台server来支撑搜索。可是有时候域名解析不是特别的稳定。并且我们发现用同一个keyword在不同的搜索

    2022年7月1日
    28
  • python – 获取时间戳(10位和13位)「建议收藏」

    python – 获取时间戳(10位和13位)「建议收藏」在python开发web程序时,需要调用第三方的相关接口,在调用时,需要对请求进行签名。需要用到unix时间戳。在python里,在网上介绍的很多方法,得到的时间戳是10位。而java里默认是13位(milliseconds,毫秒级的)。下面介绍python获得时间戳的方法:1、10时间戳获取方法:>>>importtime>>>t=time.time()>>>printt

    2022年10月2日
    0
  • java冒泡排序代码_Java冒泡排序

    java冒泡排序代码_Java冒泡排序一、冒泡排序:利用冒泡排序对数组进行排序二、基本概念:依次比较相邻的两个数,将小数放在前面,大数放在后面。即在第一趟:首先比较第1个和第2个数,将小数放前,大数放后。然后比较第2个数和第3个数,将小数放前,大数放后,如此继续,直至比较最后两个数,将小数放前,大数放后。至此第一趟结束,将最大的数放到了最后。在第二趟:仍从第一对数开始比较(因为可能由于第2个数和第3个数的交换,使得第1个数不再小于第2…

    2022年7月8日
    12
  • AnalyticDB for MySQL 3.0 技术架构解析

    AnalyticDB for MySQL 3.0 技术架构解析企业数据需求不断变化,近年来变化趋势日益明显,从数据的3V特性看:体积,速度和变化;BigData强调数据量,PB级以上,是静态数据。而FastData在数据量的基础上,意味着速度和和变化,意味着客户可以更加实时化、更加快速地进行数据处理。在Forrester最近的一项研究中,超过75%的…

    2022年9月17日
    0
  • python网页爬虫代码_python md5加密解密

    python网页爬虫代码_python md5加密解密#!/usr/bin/envpythonimportos,sys,subprocessdefupdate(path):f=open(file,’w’)forroot,dirs,filesinos.walk(path):fornameinfiles:line=os.path.join(root,name)(stdin,stderr)=subprocess.Popen(…

    2022年9月29日
    0
  • Hmily 源码解析 (三) —— 高效异步任务框架的使用

    Hmily 源码解析 (三) —— 高效异步任务框架的使用目录这是hmily的一个核心,hmily之所以高效就是因为hmily把日志的存储维护操作及confirm,cancel的操作通过Disruptor的异步任务框架的方式执行。关于disruptor的原理如下,我没怎么研究过。后我主要分析hmily是如何使用Disruptor这个框架。高性能队列Disruptor的使用剖析Disruptor:为什么会这么快?(一)Ringbuffer的…

    2022年5月21日
    36

发表回复

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

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