Label

创建label的参考链接:http://blog.csdn.net/c201038795050/article/details/45320405

参考地址:http://blog.csdn.net/chinahaerbin/article/details/39994261
参考地址:http://blog.csdn.net/tonny_guan/article/details/45625945

cocos2d-x lua中创建label的一些方法:

function GameScene.createLabel(  )
    -- body
    local winSize = CCDirector:getInstance():getWinSize()
    local layer = CCLayer:create()

    -- LabelTTF
    local label = cc.CCLabelTTF:create("HelloWorld","Arial",25)
    label:setPosition(cc.p(winSize.width/2,winSize.height-label:getContentSize().hieght))
    layer:addChild(label)

    -- LabelAtlas
    local label = cc.LabelAtlas:create("HelloWorld","fonts/tuffy_bold_italic-charmap.png",48,66,string.byte(""))
    label:setPosition(cc.p(winSize.width/2-label:getContentSize().width/2,winSize.height-label:getContentSize().height))
    layer:addChild(loabel)

    -- LabelBMFont
    local label = cc.LabelBMFont:create("HelloWorld","fonts/BMFont.fnt")
    label:setPosition(cc.p(winSize.width/2,winSize.height-label:getContentSize().height))
    layer:addChild(label)

    -- Label
    local label1 = cc.Label:createWithSystemFont("HelloWorld1","Arial",35)
    label1:setPosition(cc.p(winSize.width/2,winSize.height-50))
    layer:addChild(label1,1)
    local label2 = cc.Label:createWithTTF("HelloWorld2","fonts/STLITI.ttf",35)
    label2:setPosition(cc.p(winSize.width/2,winSize.height-100))
    layer:addChild(label2)
    local label3 = cc.Label:createWithBMFont("fonts/bitmapFontChinese.fnt","HelloWorld3")
    label3:setPosition(cc.p(winSize.widht/2,winSize.height-150))
    layer:addChild(label3)
    local ttfConfig = {}
    ttfConfig.fontFilePath = "fonts/Marks Felt.ttf"
    ttfConfig.fontSize = 35
    local label4 = cc.Label:createWithTTF(ttfConfig,"HelloWorld4")
    label4:setPosition(cc.p(winSize.widht/2,winSize.height-200))
    layer:addChild(label4,1)
    ttConfig.outlineSize = 4
    local label5 = cc.Label:createWithTTF(ttfConfig,"HelloWorld5")
    label5:setPosition(cc.p(winSize.width/2,winSize.height-250))
    label5:enableShadow(cc.c4b(255,255,255,128),cc.size(4, -4))
    label5:setColor(cc.c3b(255,0,0))
    layer:addChild(label5,1)

--给label设置大小,不能用setContentSize来设置大小,而是要用setDimensions来设置大小
label5:setDimensions(200,30)

--如果没有用setDimensions给label设置大小的话,想获取到label的大小,需通过getContentSize来获取到该label的大小
label5:getContentSize()

return layer
end

你可能感兴趣的:(Label)