博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cocos2d-x3.0 RichText
阅读量:6493 次
发布时间:2019-06-24

本文共 3843 字,大约阅读时间需要 12 分钟。

.h

#include "cocos2d.h"#include "cocos-ext.h"#include "ui/CocosGUI.h"#include "cocostudio/CocoStudio.h"USING_NS_CC;USING_NS_CC_EXT;using namespace ui;

RichText* _richText;            void  touchEvent(Ref *pSender, TouchEventType type);
.cpp

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);        /******************************************************************************************/        _richText = RichText::create();                _richText->ignoreContentAdaptWithSize(false);        _richText->setSize(Size(300, 500));                RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, "This color is White.", "Helvetica", 30);        RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 30);        RichElementText* re3 = RichElementText::create(3, Color3B::BLUE, 255, "This one is blue. ", "Helvetica", 30);        RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green. ", "Helvetica", 30);        RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 30);                RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "sliderballnormal.png");        cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("100.ExportJson");        cocostudio::Armature* pAr = cocostudio::Armature::create("100");        pAr->getAnimation()->play("Animation1");                RichElementCustomNode* recustom = RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr);        RichElementText* re6 = RichElementText::create(7, Color3B::ORANGE, 255, "Have fun!!", "Helvetica", 30);        _richText->pushBackElement(re1);        _richText->insertElement(re2, 1);        _richText->pushBackElement(re3);        _richText->pushBackElement(re4);        _richText->pushBackElement(re5);        _richText->insertElement(reimg, 2);        _richText->pushBackElement(recustom);        _richText->pushBackElement(re6);                        _richText->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2));        _richText->setLocalZOrder(10);                                        layout->addChild(_richText);        Button* button = Button::create("animationbuttonnormal.png", "animationbuttonpressed.png");        button->setTouchEnabled(true);        button->setTitleText("switch");        button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5));        button->addTouchEventListener(this, toucheventselector(LayoutTest::touchEvent));        button->setLocalZOrder(10);        layout->addChild(button);
void LayoutTest::touchEvent(cocos2d::Ref *pSender, TouchEventType type){    switch (type) {        case cocos2d::ui::TOUCH_EVENT_BEGAN:            log("TOUCH_EVENT_BEGAN");            break;                                            case cocos2d::ui::TOUCH_EVENT_MOVED:            log("TOUCH_EVENT_MOVED");            break;                    case cocos2d::ui::TOUCH_EVENT_ENDED:            if (_richText->isIgnoreContentAdaptWithSize())            {                _richText->ignoreContentAdaptWithSize(false);                _richText->setSize(Size(300, 500));            }            else            {                _richText->ignoreContentAdaptWithSize(true);            }            break;        case cocos2d::ui::TOUCH_EVENT_CANCELED:            log("TOUCH_EVENT_CANCELED");            break;                    default:            break;    }}

你可能感兴趣的文章
Android重构杂感
查看>>
如何分析性能测试需求
查看>>
PS常识及技巧
查看>>
WPF 自定义ProgressBar滚动条样式
查看>>
写一个百度url收录检测的web_php小工具
查看>>
block,inline和inline-block概念和区别
查看>>
开源源码搜索+读书学习
查看>>
OpenCV Face Detection
查看>>
0505.Net基础班第二十二天(委托、XML和播放器项目)
查看>>
WEB新手之sql注入
查看>>
if、for、while的详解及实例(一)
查看>>
守护进程vs 守护线程
查看>>
mysql数据库的理解
查看>>
UIWebView
查看>>
asp.net mvc中自行搭建实现工厂模式的spring.net+三层架构(更新)
查看>>
在文本元素中加上图标
查看>>
C++官方文档-常量成员函数
查看>>
BFC块级格式
查看>>
为什么要使用数据库连接池?以及用法(DBUtils)
查看>>
装饰器 未完待续。。。
查看>>