--创建系统字体标签
--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);