[英]Cannot use custom font in Cocos2d-x project
This code works: 此代码有效:
auto label = LabelTTF::create(CokeStore::name, "Marker Felt", 170);
But none of these work: 但这些都不起作用:
auto label = LabelTTF::create(CokeStore::name, "Coca Cola ii", 170);
auto label = LabelTTF::create(CokeStore::name, "CocaColaii", 170);
auto label = LabelTTF::create(CokeStore::name, "cocacolaii", 170);
I imported all the fonts as resources into my project and added fonts' path into Fonts provided by application
of Info.plist
. 我将所有字体作为资源导入到我的项目中,并将字体的路径添加到
Info.plist
Fonts provided by application
Info.plist
。 I'm using Cocos2d-x v. 3
, the latest version from Github. 我正在使用
Cocos2d-x v. 3
,这是Github的最新版本。
Anybody can help me with this? 有谁可以帮我这个? Is there anything wrong with my code and how to fix them?
我的代码有什么问题以及如何修复它们? Thanks for your help!
谢谢你的帮助!
I was facing alot of difficulty adding a custom font. 我在添加自定义字体时遇到了很多困难。 I know the question has already been answered but I just want to share what solved the problem for me.
我知道问题已经得到解答,但我只是想分享一下为我解决问题的方法。 These are the points you need to ensure to use a custom font:
以下是确保使用自定义字体所需的要点:
Font name must match the PostScript name of that font (you can easily find the postscript name using the Font Book, just select the font and press command+i) , so your font name should be: PostScriptName.ttf 字体名称必须与该字体的PostScript名称匹配(您可以使用字体书轻松找到postscript名称,只需选择字体并按下命令+ i),因此您的字体名称应为:PostScriptName.ttf
In the Info.plist of your project, make sure to add the font name under "Fonts provided by application", just put in the font name and extension for item0 or whatever the length of your font stack is: PostScriptName.ttf, Now, the next step that solved the issue for me was: 在项目的Info.plist中,确保在“应用程序提供的字体”下添加字体名称,只需输入item0的字体名称和扩展名,或者字体堆栈的长度为:PostScriptName.ttf,Now,为我解决问题的下一步是:
Ensure that the font file exists in the "Copy Bundle Resources" Section of the 'Build Phases' settings for your project. 确保项目的“构建阶段”设置的“复制包资源”部分中存在字体文件。 For me it somehow wasnt there and thats why the font wasnt loading, so I just manually added it.
对我来说它不知道那里,那就是为什么字体没有加载,所以我只是手动添加它。
Now you can use it even with LabelTTF::create("Text", "PostScriptName", 24)! 现在你甚至可以使用LabelTTF :: create(“Text”,“PostScriptName”,24)!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.