hzlov
December 22, 2014, 4:53pm
#1
I placed different TTF files on different directory.
/Resources/path/fontA/font.ttf
/Resources/path/fontB/font.ttf
And I like to change TTF with FileUtils::setSearchPaths
.
So, here is what I tried.
std::vector<std::string> paths;
paths.push_back("path/fontA/");
FileUtils::getInstance()->setSearchPaths(paths);
auto labelA = Label::createWithTTF("ABCDEF", "font.ttf", 50.f);
std::vector<std::string> paths;
paths.push_back("path/fontB/");
FileUtils::getInstance()->setSearchPaths(paths);
auto labelB = Label::createWithTTF("ABCDEF", "font.ttf", 50.f);
This seems not working.
labelB
shows with path/fontA/font.ttf
.
This is just simple example code.
What I’m trying to do is changing whole Text
or Label
on screen with another TTF.
How can I achieve this?
That is because the font is cached and so it doesn’t load the second font.ttf, it just uses the first one.
hzlov
December 22, 2014, 4:59pm
#3
Can’t I clear the font cache by code?
You probably can, or load both fonts manually and use the one you want. I’m not in front of a computer right now so I can’t check, but I’ll take a look later, if you haven’t figured it out.
hzlov
December 22, 2014, 5:07pm
#5
@mannewalis Thank you for your help.
I’ll wait for good news.
1 Like
hzlov
December 25, 2014, 3:23pm
#6
@mannewalis any news for this?
Yes, sorry for the late reply, the whole Christmas thing happened
So caching is the problem, but there is a simple fix. Instead of setting the search path to the actual font folder, set it one higher, like this…
std::vector<std::string> path;
path.push_back("path/");
FileUtils::getInstance()->setSearchPaths(path);
Now create the labels like this…
auto labelA = Label::createWithTTF("ABCDEF", "fontA/font.ttf", 50.f);
auto labelB = Label::createWithTTF("ABCDEF", "fontB/font.ttf", 50.f);
Justin
hzlov
December 25, 2014, 4:34pm
#8
Thanks for reply.
I knew your codes works.
But the problem is using cocostudio json files.
cocostudio is great for compositing UI, so I love to use it.
and the exported json files have static font paths by cocostudio, like “fontPath/font.ttf”.
So, I want to set search path so that using another ttf instead of the ttf which I set in cocostudio.