Under the Cocos2d-x platform, Cceditbox is often used to do the input box, but sometimes when porting to the Android platform, there will be the position of the situation, studied for the following reasons:
The Cceditbox of Android and iOS are all implemented separately by the corresponding platform controls.
1. Android below is the use of relative coordinates, in fact, like other cocos2d-x positioning is good, do not need special treatment.
2. iOS below is the use of global coordinates, for the entire screen positioning can be.
In both cases, my solution is to customize the platform-related code through macros.
If my version of the iOS platform defines macro OS X, then my code is as follows:
Add input Default anchor point (0.5,0.5), modify also useless, and then this coordinate can not be used based on layer
//coordinates, must be based on the screen coordinates
m_tf_input = cceditbox::create (Ccsizemake (280 * 0.5, 60* 0.5), ccscale9sprite::create ("Ui_blank.png"));
M_tf_input->setfontcolor (ccwhite);
M_tf_input->setplaceholder (Languagemanager::sharedlanguagemanager ()->getlocalizedstring ("Click here and Input "). C_STR ());
M_tf_input->settext ("");
M_tf_input->setmaxlength (max_chat_msg_length);
M_tf_input->setreturntype (kkeyboardreturntypesend);
M_tf_input->setdelegate (this);
This->addchild (m_tf_input);
#ifdef OS X
m_tf_input->setposition (CCP (
m_originpoint.x + this->getposition (). x + M_ Size.width * 0.5 -130 *0.5f,
M_originpoint.y + this->getposition (). Y + m_size.height* 0.5 -184 *0.5f) );
#else
m_tf_input->setposition (Inputbgimage->getposition ());
#endif