cocos2d-xcclabelttf

Get Text dimmensions on CCTextFieldTTF


Hi I want to know the width of the text inside the CCTextFieldTTF but I can't find a way to do it, I want this width so I can move a CCLabelTTF in that position so it can be like a cursor for the CCTextFieldTTF

Thanks


Solution

  • So I came up with an idea that really works

    In CCTextFieldTTF.h declare a new method

    float getTextDimensions();
    

    And in your .cpp

    float CCTextFieldTTF::getTextDimensions()
    {
        return CCLabelTTF::getContentSize().width;
    }
    

    And know just call your CCTextFieldTTF object

    m_pTextField->getTextDimensions()
    

    And do whatever you like with it