So in my team we needed to create some text fields and our clients wanted the text field to have a blink cursor so we came with this idea that really helps
In CCTextFieldTTF.h declare a new method
float getTextDimensions();
And in your .cpp
float CCTextFieldTTF::getTextDimensions()
{
return CCLabelTTF::getContentSize().width;
}
In your textfield create a new label with an action
m_pTextFieldAction = cocos2d::CCRepeatForever::create((cocos2d::CCActionInterval*)cocos2d::CCSequence::create(cocos2d::CCFadeOut::create(0.25),cocos2d::CCFadeIn::create(0.25),0));
m_pTextFieldAction~~>retain;
cursorLabel = CCLabelTTF::create,alignment);
cursorLabel~~>setVisible(false);
cursorLabel~~>setColor;
cursorLabel~~>setPosition(ccp(0,0));
addChild(cursorLabel,0);
cursorLabel~~>runAction;@
Overload the onClickTrackNode method and make the cursorLabel visible when the user clicks the target textfield
cursorLabel~~>setVisible(true);
Then overload an update method for yout textfield and do the next thing where you call your created method
if(cursorLabel~~>isVisible)
{
cursorLabel~~>setPositionX(m_pTextField->getTextDimensions()/2);
}
If everyhing goes right you should have a cursor blinking in your textfield