The simplest method is to use CCTextFieldTTF to set the graph password,
First, the class inheritance relationship
class Login:public cocos2d::CCLayer,CCIMEDelegate,CCTextFieldDelegate
There are several methods
// CCTextFieldDelegatevirtual bool onTextFieldAttachWithIME(CCTextFieldTTF * pSender);virtual bool onTextFieldDetachWithIME(CCTextFieldTTF * pSender);virtual bool onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen);virtual bool onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen);virtual bool onDraw(CCTextFieldTTF * pSender);
Add the following code to the bool Login: onTextFieldInsertText (CCTextFieldTTF * pSender, const char * text, int nLen)
Int count = (pSender-> getCharCount ()> 0? (PSender-> getCharCount (): 1 );
If (count <= 0)
{
Count = 1;
}
Std: string paSt (count ,'*');
PSender-> setString (paSt. c_str ());
In this way, each input character changes the previous character to "*".
After receiving the input, the bool Login: onTextFieldDetachWithIME (CCTextFieldTTF * pSender) Method
Std: string pstr = pSender-> getPlaceHolder ();
If (pstr = "password ...")
{
Std: string * inpstr = pSender-> m_pInputText;
Std: string showstr (inpstr-> c_str (), 0, inpstr-> length ()-1 );
PSender-> setString (showstr. c_str ());
}
In this way, all are displayed as "*".
Note that here pSender-> m_pInputText; an error is reported. Go to CCTextFieldTTF. h and set m_pInputText to public!
This method may be faulty! Because the framework source code has been modified! But I haven't found it yet! I am also studying. I hope you will pay attention to the discussion if you find any problems!