lua笔记 文字简单实用

 

--创建系统字体标签
--text                 文字
--font                 字体
--fontSize             字体大小
--dimensions         label尺寸
--hA                 水平对齐方式
--vA                 垂直对齐方式
function FontConfig.createWithSystemFont(text, fontSize, color, dimensions, font, hA, vA)
    if isEmptyString(text) then
        text = ""
    end

    if isEmptyString(font) then
        font = "Arial"
    end

    if isEmptyString(fontSize) then
        fontSize = 20
    end

    if isEmptyTable(dimensions) then
        dimensions = cc.size(0,0)
    end

    hA = hA or cc.TEXT_ALIGNMENT_CENTER
    vA = vA or cc.VERTICAL_TEXT_ALIGNMENT_CENTER

    local label = cc.Label:createWithSystemFont(text, font, fontSize, dimensions, hA, vA)
    if color then
        label:setColor(color)
    end

    return label
end

 

 

--创建数字标签
--text                 文字
--path                 数字图片路径
--width             单字符宽
--height             单字符高
--startCharMap         起始字符
--replaceChar         替换字符 根据ascii码表 

function FontConfig.createWithCharMap(text, path, width, height, startCharMap, replaceChar)
    if isEmptyTable(replaceChar) then
        replaceChar = {}
    end

    if type(text) == "number" then
        text = tostring(text)
    end

    for k,v in pairs(replaceChar) do
        text = string.gsub(text,v[1],v[2]);
    end

    local label = cc.Label:createWithCharMap(path, width, height, string.byte(startCharMap))
    label:setString(text)
    label:setAnchorPoint(0.5,0.5)
    label.replaceChar = replaceChar

    return label
end

 

用法:

local changesMoney = FontConfig.createWithCharMap("22","activity/yuebao/yeb_zitiao.png",27,38,"0")

local text = FontConfig.createWithSystemFont("正在进入游戏",30,FontConfig.colorWhite);

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值