Cursor with TextField Cocos2dx 3.0

Cursor with TextField Cocos2dx 3.0
0.0 0


Is getting a cursor to show in the TextField GUI Widget possible?


Possibly use code from here:


Added a simple blinking cursor, now need to allow touch to change the insertion point.


I’m trying out Your code with the latest cocos version and for some reason it does not work - the label is not being shown. Any idea what could be the reason? Did something change?


This was mostly a hack, that while worked was only an interim solution.
The latest cocos version should have cursor support using the engine’s TextField.

I’ve updated the gist to what I currently use, though again you could probably just use the engine’s TextField.
Mine is now mainly a wrapper to add a background image. .


Wow! There are indeed methods to set the cursor but it’s still not visible :confused:
My code that I currently use just to check if the cursor works looks like this:

auto textField = cocos2d::ui::TextField::create("Username", "Marker Felt.ttf", 48);
textField->setPosition(Vec2(getContentSize().width/2, getContentSize().height/2));

What else do I need to set to enable the cursor?


Thers is another implentaton:


To be honest I don’t understand. Where is this other implementation? What do I need to import/add to my project so I can use this other implementation (extension)?

And I still don’t know what’s wrong with my code above.

I was able to make it work. HOWEVER! I don’t know if it’s only the case in my example or the blinking cursor is working with only one type of font: Thonburi.ttf

WHY IS IT LIKE THIS!?! :open_mouth:


You can take a look about this editor:

showcase of the extension UITextField: (2.3 MB)


Am I mistaken or is this editor only available for Windows? If so I can’t use it :frowning:

Still interested in the native TextField and it’s problems with cursor :wink:


Have you tried the ui::EditBox? It’s a native, probably doesn’t look as good, but supports all regular features. On android I believe both just open a separate native text field regardless?

CocoStudio is deprecated and no longer updated since a few years back.

The parsing library has various UI components or wrappers on top of widgets that help with rendering the CocoStudio scene definitions and its nodes hierarchy.

You may be able to use TextFieldEx by itself without having to use anything related to CocoStudio itself. But you’ll have to figure out how to create and set the fields on an instance of it properly.