Label cocos2dx lua

local conSize = { width = size1.width,height = 100 }
-- 内容,字体,字号,文本size,左右对齐,上下对齐
local contentTxt = cc.LabelTTF:create("",CNFONT,32,conSize,cc.TEXT_ALIGNMENT_LEFT,cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM)
contentTxt:setAnchorPoint(cc.p(0.5,0))
contentTxt:setPosition(visibleSize.width/2,visibleSize.height/6+60)
self.mLoadLayer:addChild(contentTxt,3)

local textList = GetLoadTipsList()
local num = math.random(1,#textList)
contentTxt:setString(textList[num].showTxt)
contentTxt:enableOutline(cc.c4b(255, 255, 255, 255), 1)        -- 字体描边
contentTxt:enableShadow(cc.c4b(0, 0, 0, 255))                  -- 阴影
contentTxt:setColor(cc.c4b(255,255,255,255))                   -- 颜色

-- 上下对齐方式
cc.VERTICAL_TEXT_ALIGNMENT_TOP,
cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM,

-- 左右对齐方式
cc.VERTICAL_TEXT_ALIGNMENT_LEFT,
cc.VERTICAL_TEXT_ALIGNMENT_CENTER,

cc.VERTICAL_TEXT_ALIGNMENT_RIGHT,


-- 富余字体

self.openCostLabel = ccui.RichText:create()
self.openCostLabel:ignoreContentAdaptWithSize(false)
self.openCostLabel:setContentSize(cc.size(400,50))

local conSize = 33
local str1 = "花费"
local res1 = ccui.RichElementText:create(1,cc.c3b(255,255,255),255,str1,CNFONT,conSize)
local str2 = tostring(self.buySoldierNum)
local res2 = ccui.RichElementText:create(2,cc.c3b(255,255,255),255,str2,CNFONT,conSize)
local res3 = ccui.RichElementImage:create(3,cc.c3b(255,255,255),255,gLabelDiamondFile)
local str3 = "解锁士兵"
local res4 = ccui.RichElementText:create(4,cc.c3b(255,255,255),255,str3,CNFONT,conSize)
self.openCostLabel:pushBackElement(res1)
self.openCostLabel:pushBackElement(res2)
self.openCostLabel:pushBackElement(res3)
self.openCostLabel:pushBackElement(res4)

local pos = cc.p(self.buySoldierCostn:getPosition())
local pos2 = self.dataRoot2:convertToWorldSpace(pos)
self.openCostLabel:setPosition(pos2)
self.openCostLabel:setAnchorPoint(cc.p(0.5,0.5))
self:addChild(self.openCostLabel,10)


-- self.openCostLabel:removeElement(0)
-- self.openCostLabel:insertElement(re1,0)
-- self.openCostLabel:setContentSize(cc.size(innerWidth - margin,innerHeight)) 

RichText 在cocos2dx3.2 有个bug,直接加在cocostudio导出的层(相对布局) 不能通过setPosition设置位置,在创建的layer 和scene及可以。。。搞不懂,cocos的test中RichText在导出的json文件层了是可以设置位置的,可能是因为绝对布局。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值