cocos2d中三种“label”的区别

来源:互联网 发布:网易邮箱网络连接失败 编辑:程序博客网 时间:2024/06/15 17:51

CCLabelTTF

最常用的一种,不过效率不是很高,尤其是对于只显示数字的label一般不要用这个,因为每调用一次setstring方法就要重新创建一个openGL纹理。

    CCLabelTTF *label = [CCLabelTTF labelWithString:@"the string"  fontName:@"Marker Felt" fontSize:21];

           [layer addChild:label];

           label.position = ccp(100,100);

           [label setString@“change string”]; //修改文字的方法

CCLabelBMFont

这个label使用比较麻烦,首先你得加载好字体文件(字体图片png格式和字体坐标文件fnt格式)。

    CCLabelBMFont *label =[CCLabelBMFont labelWithString:@"the string"   fntFile:@"konqa32-hd.fnt"];

           [layer addChild:label];

           label.position = ccp(100,100);

           [label setString@“change string”];

CCLabelAtlas

如果仅仅显示数字而不涉及到文字和字符首选的label应该是这个,

   CCLabelAtlas *label = [CCLabelAtlas labelWithString:@"12" charMapFile:@"fps_images.png" itemWidth:12 itemHeight:18 startCharMap:'.'];

          [layer addChild:label];

          label.position = ccp(100,100);

          [label setString@“34”];