Lua里重写Label问题,请高手来帮忙

重写了下Label,但是对Lua语法不太懂,还请高手来帮忙看看

local MyLabel = class("MyLabel",function( strMapFile )
    return self:createNumber(strMapFile)
end)

function MyLabel:createNumber( strMapFile )
    local texture = cc.Director:getInstance():getTextureCache():addImage(strMapFile)
    local tileWidth = texture:getPixelsWide() / 10
    local label = cc.Label:createWithCharMap(texture,tileWidth,texture:getPixelsHigh(),'0')
    if label then 
        return label
    end
end

function MyLabel:setNumber( n, showBit )
end

return MyLabel

开头如果这样写

local MyLabel = class(“MyLabel”,function( strMapFile )
return cc.Label:create()
end)

那,创建的对象就没办法调用setNumber了



local MyLabel = class("MyLabel",function( strMapFile )
    local texture = cc.Director:getInstance():getTextureCache():addImage(strMapFile)
    return cc.Label:createWithCharMap(texture,texture:getPixelsWide() / 10,texture:getPixelsHigh(),'0')
end)

function MyLabel:setNumber( n, showBit )
    local strNumber = tostring(n);
    if string.len(strNumber) > showBit then
        strNumber = string.sub( strNumber, string.len(strNumber) - showBit, string.len(strNumber) )
    end
    
    if string.len(strNumber) < showBit then 
        strNumber = string.format("%02d",n)
    end
    
    self:setString(strNumber)
end

return MyLabel

重写了,能跑了,但是数字不显示,创建的Label为nil

:2: :2: :2: :2: :2: :2: :6: :6: :5: :5: :7:


local MyLabel = class("MyLabel",function( strMapFile )
--    local texture = cc.Director:getInstance():getTextureCache():addImage(strMapFile)
--    return cc.Label:createWithCharMap(texture,texture:getPixelsWide() / 10,texture:getPixelsHigh(),'0')
--      return cc.Label:createWithCharMap(strMapFile,56,79,'0')
      return cc.Label:create()
end)

这里该为cc.Label:create()可以了,但是没办法用图片显示数字了,郁闷



local MyLabel = class("MyLabel",function(strMapFile)
    local texture = cc.Director:getInstance():getTextureCache():addImage(strMapFile)
    --48 means '0'. But can't write '0'.Must write 48!
    return cc.Label:createWithCharMap(texture,texture:getPixelsWide() / 10,texture:getPixelsHigh(),48)
end)

function MyLabel:setNumber( n, showBit )
    local strNumber = tostring(n);
    if string.len(strNumber) > showBit then
        strNumber = string.sub( strNumber, string.len(strNumber) - showBit, string.len(strNumber) )
    end
    
    if string.len(strNumber) < showBit then 
        strNumber = string.format("%02d",n)
    end
    
    self:setString(strNumber)
end

return MyLabel

跟别的都没有关系,终于发现问题出在哪里了
–48 means ‘0’. But can’t write ‘0’.Must write 48!
只能写48,不能写‘0’!!!!!!!
写48就万事大吉,写‘0’就死活都出不来!!!!!!!