0

有人可以向我解释 cocos2d 如何使用 png 作为字体吗?
我想做一些类似的事情,因为我的字体只包含数字。

4

2 回答 2

1

如果你对字符串fps_images.png进行全局搜索,你的 IDE 应该会让你真正接近 cocos CCDirector 类(2.0 版)中的以下行:

FPSLabel_ = [[CCLabelAtlas alloc]  initWithString:@"00.0" charMapFile:@"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
SPFLabel_ = [[CCLabelAtlas alloc]  initWithString:@"0.000" charMapFile:@"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
drawsLabel_ = [[CCLabelAtlas alloc]  initWithString:@"000" charMapFile:@"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];

然后查找 CCLabelAtlas。您的图像必须是固定宽度的字体。

于 2012-12-26T16:45:37.073 回答
0

如果您想重用包含的相同图像来制作除 FPS 显示之外的其他内容,则以下代码应该可以工作:

    CCLabelAtlas *scoreLabel = [[CCLabelAtlas alloc]  initWithString:@"00.0" charMapFile:@"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];

然后将其设置为您想要的数字,如下所示:

    [scoreLabel setString:[NSString stringWithFormat:@"%d", (int)score]];
于 2012-12-28T06:04:12.230 回答