CCLabelTTF working in simulator but not in device - cocos2d-iphone

this code is working in simulator. when we load into the device it is not working.In console it is showing error as:
Unable to load font BARBATRI.ttf
My code is:-
CCLabelTTF *score = [CCLabelTTF labelWithString:[NSString stringWithFormat:#"Score : %d",[CommonUserDetails sharedUserDetails].GameScore] fontName:#"BARBATRI.ttf" fontSize:18];
score.position = ccp(240,160);
score.anchorPoint = ccp(0.5, 0.5);
[self addChild:score];

Add this font to your project resources and to your info.plist file to "Fonts provided by application" section. It is possible, that you have this font in Mac OS, but there is no such font in iOS.

Related

Qt Image won't show up in button

I am creating a Qt application and I have an image that I want to use for a button instead of text. Unfortunately all that shows up is an empty button.
I've tried two different methods to get it to show up with the same results for both methods.
Code for Method 1:
ui->setupUi(this);
QPixmap pix(":/svg/resources/menu.svg");
int w = ui->menuButton->width();
int h = ui->menuButton->height();
ui->menuButton->setMask(pix.scaled(w,h,Qt::KeepAspectRatio).mask());
I found the info for the second method here: Adding image to QPushButton on Qt
Code for Method 2:
ui->setupUi(this);
QIcon icon(":/svg/resources/menu.svg");
ui->menuButton->setIcon(icon);
Could someone please help me figure out why my image isn't showing up and the button is just empty?
In my project using .svg images as button icons are no problem, maybe the button size is missing, try:
ui->menuButton->setIcon(QIcon(":/svg/resources/menu.svg"));
ui->menuButton->setToolTip("optional tooltip");
ui->menuButton->setFixedSize(QSize(28,28));
Assuming you stored your icons correctly in a resource file. If not, create a new:
right click on your top project folder (in the project-tree) -> Add new.. -> choose Qt on the left an Qt Resource File on the right window -> a new Window apears.
Add Prefix -> Add Files (your icon)
You use .svg image format. Are you sure your application load image format plugin for .svg? Image plugins must be in directory "imageformats" in current directory of your application. Avaliable plugins you can find in Qt directory .../Desktop/Qt/<version>/<mingw or msvc>/plugins/imageformats

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

Use custom font in cocos2d-x v3 in iOS

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

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.