Editbox font setFontName is not working

Editbox font setFontName is not working

editName = ui::EditBox::create(Size(200, 40), ui::Scale9Sprite::create(“back.png”));
editName->setFont(“AmsiPro-Black.ttf”, 20);

editName = ui::EditBox::create(Size(200, 40), ui::Scale9Sprite::create(“back.png”));
editName->setFont(“font.fnt”, 20);

I want to change the font or I want to set fnt font file but it does not work. @slackmoehrle please help me
i use cocos2dx 3.17

1 Like

why doesn’t it work? Are there any messages on the console?

it always shows me default font while typing in edit text .
does not matter whatever font I set in this .
please try this you will find an error .
this support only some selected system font

send me a more complete code example that I can drop into a new project, please.

Archive 3.zip (135.1 KB)

this is code and get resource from zip file

 // this "AmsiPro-Black.ttf" font should be display while typing but its not that

auto editName = ui::EditBox::create(Size(168, 107), ui::Scale9Sprite::create("g3_2_ans_box.png"));
editName->setFont("AmsiPro-Black.ttf", 50);
// this "font.fnt" font should be display while typing but its not that

   auto editName1 = ui::EditBox::create(Size(168, 107), ui::Scale9Sprite::create("g3_2_ans_box.png"));
   editName1->setFont("font.fnt", 50);

Thank you, I’ll take a look

any update ?

What platforms did you test on? Is the ttf file put in correct position? May be you should show the project file.

1 Like

I test in ios for now.
I try to put ttf in the resources folder
and also i try to put ttf in resources/font folder.

what should i show you ?

@PatriceJiang please take a look.

Did you register fonts in Info.plist https://github.com/cocos2d/cocos2d-x/blob/596da2df5bc8919382f6b166bf2db046cd4e42aa/tests/cpp-tests/proj.ios/Info.plist#L34-L58

after register fonts in info.plist ttf works but fnt font still not work

fnt font in EditBox not supported

is there any possibility?

TextField is supported fnt font but

editbox has this functionality for change input mode like

In TextField there is no method like this.

@PatriceJiang can you please reply on this ?

1 Like

you can use some “hack” to achieve the input mode

  1. self design numeric keyboard
  2. show editbox on top of a textfield / label with sprite to trigger editbox, then pass back the string