您的位置:首页 > 编程语言 > Lua

Lua封装增加CCLabel接口

2015-11-29 17:31 453 查看
添加CCLabel接口,支持Tag替换

function AddLabel( str, pos, target, tag, font, anchor, stroked, fz )
if( font == nil ) then
font = G_Font_White
end
if( anchor == nil ) then anchor = ccp( 0.5, 0.5 ); end
if( tag == nil ) then tag = 0; end
if( tag ~= 0 and target:getChildByTag(tag) ) then
target:removeChildByTag( tag, true );
end
local s, e = string.find(font.name, ".fnt")
local label
local fontSize = fz
if fontSize == nil then
fontSize = font.size
end
if s then
label = CCLabelBMFont:create( str, font.name )
label:setScale(fontSize)
else
label = CCLabelTTF:create( str, font.name, fontSize )
if stroked or font.stroked then
AddStrokeOnLabel( label )
end
end

label:setPosition( pos )
label:setAnchorPoint( anchor )
label:setColor( font.color )
target:addChild( label, 0, tag )

return label;
end


font参数类型如下:

G_Font_YellowStroke_Small = {
name = "DFPYuanW7-GB.ttf",
size = 12,
color = ccc3(251,224,114),
stroked = true
}


EX:

AddLabel( "文字", ccp(10,12), father, 0, G_Font_YellowStroke_Small, ccp(0.5, 0.5))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Lua cocos2d tag CCLabel