CCLabelAtlas 特效 自定义CCLabelTTF
有时候游戏中要用到一些特殊的字体效果,特别是数字。 CCLabelAtlas就可以从png图中读取文字。 CCLabelAtlas* diceCount=CCLabelAtlas::labelWithString("1:", "nums_font.png", 14, 21, '0'); 第一个参数:显示的内容:1x,你也许会奇怪为什么是1x,因为使用的png图必须是连续的,因为程序内部是议连续的scall码识别的。9的后一位的”:“,所以先实现x就得用”:“代替。 第二个参数:图片的名字 第三个参数:每一个数字的宽 第四个参数:每一个数字的高 每五个数字:开始字符 以前看过这样一个例子 也不错 完全通过代码实现的 研究了一下 找不到任何显示多位数的规律还是plist 万岁啊! +(CCRenderTexture*) createStroke: (CCLabelTTF*) label size:(float)size color:(ccColor3B)cor { CCRenderTexture* rt = [CCRenderTexture renderTextureWithWidth:label.texture.contentSize.width+size*2 height:label.texture.contentSize.height+size*2]; CGPoint originalPos = [label position]; ccColor3B originalColor = [label color]; BOOL originalVisibility = [label visible]; [label setColor:cor]; [label setVisible:YES]; ccBlendFunc originalBlend = [label blendFunc]; [label setBlendFunc:(ccBlendFunc) { GL_SRC_ALPHA,GL_ONE }]; CGPoint bottomLeft =ccp(label.texture.contentSize.width * label.anchorPoint.x + size, label.texture.contentSize.height * label.anchorPoint.y + size); CGPoint positionOffset =ccp(label.texture.contentSize.width * label.anchorPoint.x - label.texture.contentSize.width/2,label.texture.contentSize.height * label.anchorPoint.y - label.texture.contentSize.height/2); CGPoint position = ccpSub(originalPos, positionOffset); [rt begin]; for (int i=0; i<</span>360; i+=30) // you should optimize that for your needs { [label setPosition:ccp(bottomLeft.x + sin(CC_DEGREES_TO_RADIANS(i))*size, bottomLeft.y + cos(CC_DEGREES_TO_RADIANS(i))*size)]; [label visit]; } [rt end]; [label setPosition:originalPos]; [label setColor:originalColor]; [label setBlendFunc:originalBlend]; [label setVisible:originalVisibility]; [rt setPosition:position]; return rt; } CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64]; // ask director the the window size CGSize size = [[CCDirector sharedDirector] winSize]; // position the label on the center of the screen label.position = ccp( size.width /2 , size.height/2 ); // add the label as a child to this Layer [label setColor:ccYELLOW]; CCRenderTexture *stroke=[SomeUtilityClass createStroke:label size:3 color:ccBLACK]; [self addChild:stroke]; [self addChild:label];