ColorLabel = {} ColorLabel.__index = ColorLabelcode
function ColorLabel:create( w , h , fontSize ) instance = {}string
setmetatable( instance , ColorLabel ) instance.mSize = CCSize( w , h ) instance.mPoint = ccp(0,h) instance.rt = CCRenderTexture:create( w , h ) instance.fontSize = fontSize instance.layer = CCSprite:create() instance.layer:setContentSize( CCSize( w , h ) ) instance.layer:addChild( instance.rt ) return instance
endit
function ColorLabel:addString( str , fontName , fontColor ) local pos = 1 local fontSize = self.fontSize local width = self.fontSize local point = self.mPoint while pos <= str:len() do local l = 2 if string.byte(str, pos) >0x80 then l=3 width = fontSize else l=1 width = fontSize / 2 end local label = CCLabelTTF:create(str:sub(pos , pos+l-1),fontName,fontSize) label:setColor(fontColor) label:setAnchorPoint( ccp(0,1) ) self.rt:begin() label:setPosition( point ) label:visit() self.rt:endToLua() pos = pos + l point.x = point.x + width if point.x > self.mSize.width - width then point.x = 0 point.y = point.y - fontSize endio
end self.mPoint = point
endtable
--[[ cl = ColorLabel:create( 200 , 200 , 40 )function
cl.layer:setPosition(ccp(500,500)) cl:addString( "【我是屌絲】" , "Black" , ccc3(255,255,255) ) cl:addString( "得到【武器裝備啊】" , "Black" , ccc3(0,255,255) ) scene:addChild( cl.layer )
--]]meta