cocos2d-x3.0 RichText
2024-10-18 22:27:33
.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;
}
}
最新文章
- .NET Core系列 : 1、.NET Core 环境搭建和命令行CLI入门
- [NodeJS] 优缺点及适用场景讨论
- python generator next send
- 硕士研究生入学考试复试试卷答案.tex
- Swift泛型协议的N种用法
- IIS7 配置
- Java 读写方案
- .NET程序编译和运行
- 解决FPDF报错:FPDF error: Not a JPEG file / FPDF error: Not a PNG file
- .Net跨平台中遇到的问题小结
- TOGAF架构内容框架之架构交付物
- CSS选择器大汇总
- 使用nginx sticky实现基于cookie的负载均衡
- ThreadPoolExecutor 学习笔记
- IOS跟ANDROID的区别
- mysql 数据库 命令行的操作——对表和字段的操作
- C#获取H5页面上传图片代码
- WebForm发送邮件
- Latex表格太宽处理方法 (How to shorten Latex table length)
- [Grunt] Development Automation Tasks with Grunt
热门文章
- Description Resource Path Location Type The superclass ";javax.servlet.http.HttpServlet"; was not foun
- Java事务管理之JDBC
- HTML5练习1
- OpenCV持久化(一)
- Spark(十三)SparkSQL的自定义函数UDF与开窗函数
- Codeforces Round #213 (Div. 1) B - Free Market 思维+背包 好题
- Code First 数据库迁移
- thinkphp3.2开启静态缓存与缓存规则设置
- 谷歌pagerank算法简介
- CSUOJ 1270 Swap Digits