Hey All,
I am using TTF fonts and its working fine on iOS devices but its not working on android devices. Font name and file name is both RockoUltraFLF and I have placed it in resources folder.
Hey All,
I am using TTF fonts and its working fine on iOS devices but its not working on android devices. Font name and file name is both RockoUltraFLF and I have placed it in resources folder.
try setting the name of the font to fonts/yourfontname.ttf, and put your font under fonts folder under resources
create the fonts folder if not there
example:
CCLabelTTF *item1Text = CCLabelTTF::create("Info", "fonts/atarist.ttf", 10.0);
You know what I am facing very strange issues.
I have my font in resources folder (no sub folder), I have added my font in info.plist as âfonts/RockoUltraFLF.ttfâ and I am using it in my code as CCLabelTTF::Create(âtextâ,âRockoUltraFLFâ,10);
Lolz what is happening and Its working fine only on IOS but not on android.
Yourâre doing it wrong. Only iOS/Mac search fonts in Info.plist and can use font name instead of path to font file. On other systems, you should use relative path to you font file, starting from resource folder as root. I.e if you have no subfolders, just use âRockoUltraFLF.ttfâ
CCLabelTTF *item1Text = CCLabelTTF::create("Info", "RockoUltraFLF.ttf", 10.0);
P.S. Prefer Factory pattern over macro defines and copy&paste. For example, you can create class CCLabelTTFUtils
which have static method
static CCLabelTTF *create(const std::string &text, float fontSize).
Guess what
I placed the font file in fonts folder and removed entry from info.plist , I used in code as âfonts/RockoUltraFLF.ttfâ and Its now working on android but not on iOS. I guess we need to make android build first and then change code to work in iOS and then make iOS build.
but I wonder why iOS part isnât working. Adding font entry in info.plist is required i think, other wise it wont work on iOS.
Thanks for the help
allow me to explain
I checked the source code of cocos2dx a few months ago(cant remember which class it was),
the only reason why it works in ios is, it looks for it under resources
where as when android is detected it will look for it under âfonts/â, it is harcoded in the sourcecode
so place your font under both folders and should work
thats all
In android the font name goes like this - âfonts/FontName.ttfâ for iOS its just âfontNameâ. Use appropriate macros or follow the method used in the Tests project. There is no need to change the code everytime.
regards,
Raghu S
metin lapo wrote:
where as when android is detected it will look for it under âfonts/â, it is harcoded in the sourcecode
No, it doesnât hardcoded.
Thanks alot guys, with discussion here I finally managed to figure out the solution and now I understand why fonts can cause low memory since it has to be used as a static array of fonts with device platform check.
Right, itâs just a name of the relative path, you could name it whatever else rather than âfonts/â.
Sergey Shambir wrote:
metin lapo wrote:
> where as when android is detected it will look for it under âfonts/â, it is harcoded in the sourcecode
No, it doesnât hardcoded.
Mehroze Yaqoob wrote:
Hey All,
>
I am using TTF fonts and its working fine on iOS devices but its not working on android devices. Font name and file name is both RockoUltraFLF and I have placed it in resources folder.
remove the .ttf extension in case of android for the file name in the code. You then do not to give a folder reference like âfont/abc.ttfâ, simply pass âabcâ as a font name. I have done in my 2-3 games and it works 100%.
CCLableTTF * font = CCLabelTTF::create(âabcâ, âHelveticaâ, 20);
James Chen wrote:
Right, itâs just a name of the relative path, you could name it whatever else rather than âfonts/â.
>
Sergey Shambir wrote:
> metin lapo wrote:
> > where as when android is detected it will look for it under âfonts/â, it is harcoded in the sourcecode
> No, it doesnât hardcoded.
hi James Chen,
When I use SystemFont on ios like âHelvetica-Bold.ttfâ it works fine._
CCLabelTTF * font = CCLabelTTF::create(âanythingâ, âHelvetica-Bold.ttfâ, 20); <â works fine on ios_
but when i do samething for android it does not work.
Previously if I use system font as a regular like âHelvetica.ttfâ it works on ios and on android in a different way
CCLabelTTF * font = CCLabelTTF::create; <â- on ios works well
CCLabelTTF * font = CCLabelTTF::create; <â- on android it works in this way
CCLabelTTF * font = CCLabelTTF::create; <â- on ios works well
CCLabelTTF * font = CCLabelTTF::create; <â- on android not works
The last example is not working any idea
âHelveticaâ seems to be a system font on android. So you donât need to add .ttf probably, while âHelvetica-Boldâ is not a system font, therefore, it canât work on android.
If you put .ttf files to the root of resource path.
CCLabelTTF * font = CCLabelTTF::create("anything", "Helvetica.ttf", 20);
should both work for android and iOS. On iOS, you have to do one thing more, thatâs adding Helvetica.ttf to info.plist.
Refer to this if anyoneâs interested. Iâve written a simple and rough guide!
[[http://stackoverflow.com/questions/19153659/importing-fonts-for-cocos2dx-ios]]
@quiet_readonly
I donât have the font in plist and Iâm trying to use like this: âfonts/smallboldpixel.ttfâ but itâs not working. I tried also to add in plist file with/withouth relative path âfonts/smallboldpixel.ttfâ but nothing. âfontsâ folder itâs at the same level with âResourcesâ.
Can somebody help me pls?
Regards
Your structure should be like this :
Resources
âfonts
----âYourFontName.ttfâ
Now you need to add this to your Info.plist with the relative path. i . e. âfonts/YourFontName.ttfâ
When you want to use it with iOS use only âYourFontNameâ. Notice the name without extension.
When you want to use it with Android use âfonts/YourFontName.ttfâ.
This might be out of date, but my Android devices (I have two) do not have Helvetica⌠I always get LOTS of these warnings in console when running Android:
D/cocos2d-x debug info(22548): cocos2d: fullPathForFilename: No file found at Helvetica. Possible missing file.
Now I donât specifically use Helvetica, I use other actual fonts so this is not a problem ,except the logs are CRAMMEd with those warnings⌠because the Label:s in cocos2d-x are hardcoded to Helvetica until you change them?
+1 Cocos tries unsuccessfully to load âHelveticaâ as the system font every time a system font label is created. It also fails to load âsans-serifâ as a system font name. Probably should be configurable in a manifest file which font name is used for Android system font, or expose an API to allow us to specify programatically, similar to setting the sprite search paths.
for those who want only hide the log, there is this trick - but it will hide also others FileUtils log.
FileUtils::getInstance()->setPopupNotify(false);