添加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))