前端之家收集整理的这篇文章主要介绍了
cocos2dx richText,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
local function createMyRichText(fieldSize,spTb)
local rc=ccui.RichText:create()
-- node:addChild(rc)
rc:ignoreContentAdaptWithSize(false)
rc:setContentSize(fieldSize)
for key,var in pairs(spTb) do
var:setContentSize(var:getBoundingBox())
local rcItem=ccui.RichElementCustomNode:create(key,cc.c3b(255,0),255,var)
rc:pushBackElement(rcItem)
end
return rc
end
local spTb={}
local sp1=cc.Sprite:create("dog.png")
sp1:setColor(cc.c3b(0,255))
sp1:setScale(0.5)
local text1=cc.Label:createWithSystemFont("你好啊,","黑体",30)
text1:setColor(cc.c3b(255,0))
local text2=cc.Label:createWithSystemFont("我擦,","Arial",90)
text2:setScale(0.4)
text2:setColor(cc.c3b(0,225,0))
local text3=cc.Label:createWithSystemFont("孙子啊,","楷体",30)
text3:setColor(cc.c3b(0,255))
local text4=cc.Label:createWithSystemFont("苹果笔记本,","宋体",30)
text4:setColor(cc.c3b(0,255))
local text5=cc.Label:createWithSystemFont("华为,",30)
text5:setColor(cc.c3b(255,0))
local text6=cc.Label:createWithSystemFont("宏碁啊,",30)
text6:setColor(cc.c3b(127,127))
table.insert(spTb,text1)
table.insert(spTb,text2)
table.insert(spTb,text3)
table.insert(spTb,text4)
table.insert(spTb,text5)
table.insert(spTb,text6)
table.insert(spTb,sp1)
local richText=createMyRichText(cc.size(400,400),spTb)
richText:setPosition(cc.p(480,320))
ly:addChild(richText)