CCTextFieldTTF: All typed letters end up in column one


#1

I have the following code that adds a text entry field to the current layer and opens the keyboard:

CCSize size = CCDirector::sharedDirector()>getWinSize;
CCTextFieldTTF* nameEntryField = CCTextFieldTTF::textFieldWithPlaceHolder,
CCTextAlignmentLeft, “Menlo”, size.height/12);
nameEntryField
>setPosition(ccp(size.width/2, size.height*0.8));
this~~>addChild;
nameEntryField~~>attachWithIME();

I have tested this on the iPhone simulator on XCode and on my iPad 2 and in both cases, when I type the first character it shows up in the text field like expected, but subsequent characters show up in the same place, i.e. over the first character(s).

P.S: When the above code is called I get the message “Cocos2d: markedTextRange” in the console three times. This message is also printed for every key press.

What am I doing wrong? Do I need to “move the cursor” myself somehow?


#2

I now tried to create a `CCTextFieldDelegate` which I set to be the `CCTextFieldTTF`’s delegate and overrode the `onTextFieldInsertText` method and keep track of the string myself, but when I call `sender->setString(m_text.c_str())`, it overwrites the text every time, so the first letters get really blurry as they are constantly overwritten as the user types.

Any tips?

This is on iOS – tested both on an iPad and the iPhone simulator.