[英]Importing fonts for cocos2dx iOS
I've referred to this link: Using custom fonts in Cocos2d 我已引用此链接: 在Cocos2d中使用自定义字体
and this link : http://captainjor.wordpress.com/2013/04/03/cocos2d-x-custom-ttf-font/ 和此链接: http : //captainjor.wordpress.com/2013/04/03/cocos2d-x-custom-ttf-font/
The first link works but I can only specify the family name of the font (Name based on the top of the font window). 第一个链接有效,但是我只能指定字体的系列名称(基于字体窗口顶部的名称)。 If I wanted Bold, or some crazy ass styling, I cannot specify explicitly as I opened other styles fonts like BoldItalic or Italic, it still returns me the Family Name.
如果我想要Bold或某种疯狂的屁股样式,则在打开其他样式字体(如BoldItalic或Italic)时无法明确指定,它仍然会返回我的姓氏。
The second link does not work at all. 第二个链接根本不起作用。
The code I've used in Cocos2dx that works: 我在Cocos2dx中使用的代码可以正常工作:
CCLabelTTF *energyLabel = CCLabelTTF::create("ABCDEFGHIJKL", "Roboto", 60.0f);
This one doesn't: 这不是:
CCLabelTTF *energyLabel = CCLabelTTF::create("ABCDEFGHIJKL", "Roboto Black Italic", 60.0f);
Note that I've already double checked in my Info.plist file to import all the required fonts. 请注意,我已经仔细检查了Info.plist文件,以导入所有必需的字体。 Anyone has any more solutions?
还有其他解决方案吗? =/ I'm pretty stumped.
= /我很沮丧。 Importing fonts are such PITA.
导入字体就是这样的PITA。
EDIT: I've stumbled again on this issue, but in a different approach. 编辑:我在这个问题上再次跌跌撞撞,但是采用了不同的方法。 just thought I would post here a few important pointers on how I exactly do font importing for Android and iOS.
只是以为我会在这里发布一些重要的指示信息,说明如何准确地为Android和iOS导入字体。 Note that this is best for supporting the Import of fonts with ONE line of code.
请注意,这最适合支持使用一行代码的字体导入。
-> Yes we can see that I have somehow included the "fonts/" subfolder directory EVEN THOUGH the fonts are at the ROOT folder in Resources. ->是的,我们可以看到我以某种方式包含了“ fonts /”子文件夹目录,即使字体在参考资料中的ROOT文件夹中也是如此。 This is the weirdest part here and this should be only thing that's tricky.
这是最奇怪的部分,这应该只是棘手的事情。 I tried removing the "fonts/" subfolder directory reference and it DOESN'T WORK when I tried to use the font to display texts/ labels in my application
我尝试删除“ fonts /”子文件夹目录引用,但当我尝试使用字体在应用程序中显示文本/标签时,它不起作用
And this is the line that works for both iOS and Android: 这是适用于iOS和Android的行:
CCLabelTTF* levelLabel = CCLabelTTF::create("TextDisplayed", Roboto-BlackItalic.ttf, 12);
This line of code heavily relies on this fact: PostScript Name of a Font needs to be exactly the same as file name. 这行代码在很大程度上取决于以下事实:字体的PostScript名称必须与文件名完全相同。
Would you try using 你会尝试使用
"Roboto-BlackItalic"
as a font name? 作为字体名称? I have just checked in some code base of mine and I am using the font filename (without extension) rather that the proper font name and it works just fine.
我刚刚检查了我的一些代码库,并且我使用的是字体文件名(不带扩展名),而不是正确的字体名称,并且它工作正常。
EDIT: as per Joel Tay's comment, it is the Postscript font name the right one to use. 编辑:根据Joel Tay的评论,它是Postscript字体名称最适合使用的字体。 You can find it in Font Book, as the attached picture shows, by selecting Show Font Info from the Preview Menu.
通过从预览菜单中选择显示字体信息,可以在“字体书”中找到它,如所附图片所示。
You can check my answer here.- 您可以在这里查看我的答案。
UIFont custom font not displaying on device UIFont自定义字体未显示在设备上
To display all 'real' font names visible by your application. 显示应用程序可见的所有“真实”字体名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.