Solution to the problem of position offset of Cceditbox under iOS and Android platform in Cocos2d-x

Source: Internet
Author: User

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
    

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.