Use custom font in cocos2d-x v3 in iOS - c++

I'm trying to use a custom font in Cocos2d-x v3 in iOS.
I'm following these steps:
http://www.cocos2d-x.org/wiki/How_to_Use_Custom_TTF_Font_on_iOS
But when I run the app, the font doesn't appears (the label works properly, expect for the font).
This is my code:
auto playerLabel = LabelTTF::create("Player", "Aller.ttf", 32);
playerLabel->setPosition(Point(40, visibleSize.height - playerProfile->getContentSize().height - 10));
playerLabel->setColor(ccc3(1,1,1));
playerLabel->setAnchorPoint(Point(0.0f, 0.0f));
this->addChild(playerLabel,5);

Just to close the question.
The answer given by #essess in the commens worked perfectly.
Answer:
if you are using fonts/Aller.ttf in your plist file, remove the path "fonts/" instead just use Aller.ttf in the plist file

Related

Chinese characters not shown in embedded system (yocto, Qt 5.5.1) - why Qt doesn't use system fonts?

While the following code works on both, desktop Linux and Windows, chinese characters are shown like white space on an embedded linux (yocto jethrow, Qt 5.5.1, Qt on X11). It seems that Qt uses its own fonts and not the system fonts on this system. Note: after "Hello World" there should be the chinese "nihao".
C++ content of main():
QApplication a( argc, argv );
QString s = QString::fromUtf8("Hello world \u611b!");
QPushButton hello;
// eventually set font here, see below
hello.setText(s);
hello.resize( 200, 30 );
hello.show();
return a.exec();
On another embedded system which used Qt 4, it was sufficient only to install a proper font. The font is also correctly installed here and recognised by fc-list.
If I modify the code above and set the font directly, it works as expected:
// insert font here:
int id = QFontDatabase::addApplicationFont("/usr/share/fonts/wqy/wqy-microhei.ttc");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont font(family);
hello.setFont(font);
// end modification
hello.setText(s);
If I make a simple qml script, I also have to set the font.
If I use a web engine browser widget however, it can display chinese characters.
The fonts which are shown by the command "fc-list" (liberation, wqy-microhei) and with the qt function " Qt.fontFamilies()" (bitstream, luxi, dejavu, curier, cursor, utopia) are different.
Is it possible to change the qt configuration without recompiling qt or the application in order that wqy-microhei is used for the chinese characters?
Although this embedded system uses Qt on X11, the solution was to copy the font into /usr/lib/fonts as is described here:
https://doc.qt.io/qt-5/qt-embedded-fonts.html
It seems that the Qt/X11 integration is not complete on this system. The yocto meta-qt5 layer which is used as a base did not use X11 by default for this board. It was switched to X11 in order to use X11vnc.

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. I'm using Cocos2d-x v. 3, the latest version from 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
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:
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)!
In Cocos2d-x V3, there is a new class Label.
I tried this and it worked:
Label *label = Label::createWithTTF("Your string here","cocacolaii.ttf", 170);
For more details, you can read this

How can i add custom fonts in cocos2d-x

To add custom fonts in cocos2d-x i followed the following steps.
Download a font.
paste it in resource file of my project without any subfolder.
Add my font in info.plist in Fonts provided by application as Roboto-thin.ttf
Add it in Copy bundle resources.
I used the following code to display the font:
CCLabelTTF* cycleLabel1 = CCLabelTTF::create(" ", "Roboto-Thin.ttf", 80);
I tried with removing the extension also in the code, but no use. Anyone please help me to solve this problem.
On IOS, inside your CCLabelTTF::create() you have to use the NAME of the font, not the file of the font. In your case it is probably "Roboto Thin". Something like this:
CCLabelTTF* cycleLabel1 = CCLabelTTF::create(" ", "Roboto Thin", 80);
You can see font names installing them and opening them in Font Book (assuming you use mac)
Note on Android you still call fonts using its file name.
It is very explained (not very well at all) in the documentation.
http://www.cocos2d-x.org/wiki/How_to_Use_Custom_TTF_Font_on_iOS
Try this:
AddFontResource(L"xxx/yyy/Roboto-Thin.ttf");
before CCLabelTTF::create(" ", "Roboto-Thin", 80);
and then RemoveFontResource(L"xxx/yyy/Roboto-Thin.ttf");
Make sure that the name of the font and the file name are the same

Setting icons in Unity3d standalone player

I am trying to use Unity, with a build script that creates my application by ultimately invoking BuildPipeline from the script. I am trying to figure out how to set up the icons, however. After calling PlayerSettings.SetIconsForTargetGroup and invoking BuildPipline.BuildPlayer, the appropriate icon does not show up for the executable file produced, nor display when the program is running.
I am currently using the following code.
Texture2D texture = AssetDatabase.LoadMainAssetAtPath(iconFile) as Texture2D;
int [] sizeList = PlayerSettings.GetIconSizesForTargetGroup(BuildTargetGroup.Standalone);
Texture2D[] iconList = new Texture2D[sizeList.Length];
for(int i=0;i<sizeList.Length;i++)
{
int iconSize = sizeList[i];
iconList[i] = (Texture2D)Instantiate(texture);
iconList[i].Resize(iconSize,iconSize,TextureFormat.ARGB32,false);
}
PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Standalone,iconList);
What am I doing wrong?
Any assistance would be greatly appreciated. Thank you
Using BuildTargetGroup.Unknown works for me.
This also worked for me:
BuildTargetGroup.Unknown
But with an unwanted outcome: Unity does not override all icon sizes when setting one single Texture2D PNG, so Windows Explorer swaps the icon of my application EXE between the Unity default icon and my icon for different resolutions. Definitely, seems like a bug in Unity3D BuildPipeline.BuildPlayer(..) or SetIconsForTargetGroup(..).
If you're calling BuildPipline.BuildPlayer for OSX, then you need to specify full folder:
/MyPath/MyApp.app
i.e. don't leave out the ".app" part, because without that Unity builds the app, but doesn't include icons or splash image in resolution dialog.

Cocos2d-Android Custom font not working

I am trying to use custom font in Cocos2d-Android with CClabel, I have added my font file into the assets and trying to use it by name "Faraco_Hand.ttf" and "Faraco_Hand" but its not working, I have googled around but haven't found any solution. this is how my code looks a like:
currentVideoLabel = CCLabel.makeLabel(VideosLabels[currentSelected], "Faraco_Hand.ttf", winSize.width/41);
currentVideoLabel.setPosition(CGPoint.make(winSize.width/2, 20));
addChild(currentVideoLabel);
If someone know this please help me.
Hi i use this way to add font in my game here i am sharing you my code check it hope it's helpful for you here i am setting my font on label this is the only way to set fonts...all the best
Example:1
CCLabel labelcontinue = CCLabel.makeLabel("continue", "fonts/JimboStd-Black.otf", 14);
labelcontinue.setPosition(CGPoint.ccp(272, 95));
labelcontinue.setColor(ccColor3B.ccc3(165, 42, 42));
mainPaperNode.addChild(labelcontinue, 25);
Example2:
CCLabel labelWelcome = CCLabel.makeLabel("Welcome", "fonts/JimboStdBlack.otf",20);
labelWelcome.setColor(ccColor3B.ccc3(139, 69, 19));
labelWelcome.setPosition(CGPoint.ccp(innerArea.getContentSize().getWidth() / 2, (innerArea.getContentSize().getHeight() / 2) + 138));
innerArea.addChild(labelWelcome);
i know this is late reply, anyhow it may help someone who search this same thing...
CCLabel supports external fonts but some of the ttf will not recognized by android so it will through exception so better you try another font instead of this the code is same...
label = CCLabel.makeLabel("label value", "external_font_name.ttf", 30);
label.setPosition(CGPoint.make(winSize.width/2, 20));
addChild(label);
I don't think there's any problem with your method. I guess the problem is you are renaming the original font file. Rename the font file name with its original name (written in the font file itself, check attached image).
in this case, I kept my ttf file in Resources/fonts folder and wrote my code like:
CCLabelTTF* label = CCLabelTTF::create("Hello World", "fonts/A Damn Mess.ttf", 20);
Also check CCLabelTTF instead of CCLabel.
Hope this will help you.
Hai this will help. This code works for me fine. Put custom font int assets->fonts
CCLabel label1 = CCLabel.makeLabel("Points: 0", "fonts/pin.ttf", 28);
label1.setColor(ccColor3B.ccWHITE);
label1.setPosition(280f * scaleX, 550f * scaleY);
addChild(label1);