Cursor with TextField Cocos2dx 3.0

Cursor with TextField Cocos2dx 3.0
0.0 0

#1

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


#2

Possibly use code from here:


#3

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


#4

@stevetranby
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?


#5

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.
https://gist.github.com/stevetranby/2b68b9f6a1b27e9fdf34 .


#6

@stevetranby
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->setCursorChar('|');
textField->setCursorEnabled(true);
textField->setTextColor(Color4B::BLACK);
textField->setPosition(Vec2(getContentSize().width/2, getContentSize().height/2));
textField->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
addChild(textField);

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


#7

Thers is another implentaton:


#8

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.

EDIT:
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:


#9

You can take a look about this editor: https://github.com/halx99/x-studio365

showcase of the extension UITextField:
Screenrecorder-2017-11-29-18-19-54-884.zip (2.3 MB)


#10

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:


#11

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.