cocos2d-x lua项目中创建Label崩溃

2014-10-5 杜世伟 cocos2d-x

   今天使用cocos2d-x 3.2版本新建lua项目,测试lable外描边一直提示LUA ERROR:  attempt to index local 'label' (a nil value)

local function test()
        local layer = cc.Layer:create()

        local s = cc.Director:getInstance():getWinSize()

        local col = cc.LayerColor:create( cc.c4b(200, 191, 231, 255))
        layer:addChild(col)

        local ttfConfig = {}
        ttfConfig.fontFilePath = "res/fonts/arial.ttf"
        ttfConfig.fontSize = 40
        ttfConfig.glyphs   = cc.GLYPHCOLLECTION_DYNAMIC
        ttfConfig.customGlyphs = nil
        ttfConfig.distanceFieldEnabled = true
        ttfConfig.outlineSize = 0
                
        local label2 = cc.Label:createWithTTF(ttfConfig,"Glow",cc.TEXT_ALIGNMENT_CENTER,s.width)
        label2:setAnchorPoint(cc.p(0.5,0.5))
        label2:setPosition(cc.p(s.width/2, s.height * 0.6))
        label2:setTextColor( cc.c4b(0, 255, 0, 255) )
        label2:enableGlow(cc.c4b(255, 255, 0, 255))
        layer:addChild(label2)
        return layer
    end

    注意红色的那行,由于自己路径下没有指定的字体,一直提示LUA ERROR:  attempt to index local 'label' (a nil value)

    找了很长的原因,当初以为新创建的项目还需要手动开启什么来着,最后发现红色那行指定的路径不对(必须确保路径正确且指定的资源存在),否则创建的label为nil

 

 

标签: cocos2dx cocos2d-x label

Powered by emlog 沪ICP备2023034538号-1