[New Feature] CCEditBox support in cocos2d-x

Hi all,
PLZ notice that:
This Pull Request(https://github.com/cocos2d/cocos2d-x/pull/2045) fixed a bug that (fixed #1750: [iOS] CCEditBox’s position is incorrect when it’s added to a non-fullscreen CCNode.) .

@ Giannandrea Castaldi

I’m trying to solve the problem of the UITextfield that remains on the screen. I’ve found out that my CCEditBox is not released. I don’t know why but when is called editBoxEditingDidBegin the release > count is correctly 2 but when is called editBoxTextChanged it’s 3. Between these two calls I haven’t used the CCEditBox.
Any suggestion?

You could make a memory breakpoint to find out where it was retained.

roger solsona wrote:

Yes! that works! I had to put your code at EditBoxImplIOS.mm file. Thanks!
My game is running on Android devices too. Do you have any idea to make it work like this in Android?

You probably need to change the implementation of CCEditBox from UITextField to UITextView. But IMO it’s not friendly to make user jump to another scene to input something.

James Chen wrote:

roger solsona wrote:
> Yes! that works! I had to put your code at EditBoxImplIOS.mm file. Thanks!
> My game is running on Android devices too. Do you have any idea to make it work like this in Android?
>
You probably need to change the implementation of CCEditBox from UITextField to UITextView. But IMO it’s not friendly to make user jump to another scene to input something.

And there is no other way to change all placeHolders initial color to black in Android?? I don’t see where the placeHolder is initialized to Gray to change it. Do you know it?

Hi all,
I tried to change the scene but the UITextField remains in the screen. Setting a breakpoint the retain method of CCEditBox I’ve found out that probably is called once too many.
I’ve a scene built with a race CCLayer, when the race is terminated I initialize a dialog CCLayer where, in the init of this dialog, I add a CCEditBox. When the init is terminated the retainCount is correctly 2 (1 for the autoreleasepool and 1 for the add in the dialog). The strange behaviour is when I add the dialog CCLayer in the race CCLayer, during the execution of this addChild is called again the retain in the CCEditBox (I think that is not necessary).
If it can be useful I’ve added a screenshot of the stacktrace of this last call to the retain.

Thanks for the help.

Giannandrea

James Chen wrote:

@ Giannandrea Castaldi
> Now I’ve another problem. After I remove my dialog (the CClayer with added the CCLayerColor and the CCEditBox) in the screen remains the UITextfield, and it remains until I stop the process.
Any suggestion?
>
You should make sure that CCEditBox was destructed.
[…]

Hi,

I would like to put the CCEditBox text, normal text and placeHolder text, aligned to the center. Is it possible?

Thanks.

I’ve found the reason why the CCEditBox wasn’t correctly removed from the screen, in my dialog CCLayer I had redefined the onExit without calling CCLayer:onExit.
Now I’ve anther problem alsways in iOS, If I open my dialog CCLayer and close it without using CCEditBox the dialog and the CCEditBox are removed correctly without problem, if I select the CCEditBox and the keyboard is open there is no way to avoid an EXC_BAD_ACCESS Exception in the call to resignFirstResponder in EAGLView.mm:

-(void) handleTouchesAfterKeyboardShow
{
    NSArray *subviews = self.subviews;

    for(UIView* view in subviews)
    {
        if([view isKindOfClass:NSClassFromString(@"CustomUITextField")])
        {
            if ([view isFirstResponder])
            {
                [view resignFirstResponder];
                return;
            }
        }
    }
}

Any suggestion?

Thanks.

Giannandrea

Giannandrea Castaldi wrote:

Hi all,
I tried to change the scene but the UITextField remains in the screen. Setting a breakpoint the retain method of CCEditBox I’ve found out that probably is called once too many.
I’ve a scene built with a race CCLayer, when the race is terminated I initialize a dialog CCLayer where, in the init of this dialog, I add a CCEditBox. When the init is terminated the retainCount is correctly 2 (1 for the autoreleasepool and 1 for the add in the dialog). The strange behaviour is when I add the dialog CCLayer in the race CCLayer, during the execution of this addChild is called again the retain in the CCEditBox (I think that is not necessary).
If it can be useful I’ve added a screenshot of the stacktrace of this last call to the retain.
>
Thanks for the help.
>
Giannandrea
>

>

James Chen wrote:
> @ Giannandrea Castaldi
> > Now I’ve another problem. After I remove my dialog (the CClayer with added the CCLayerColor and the CCEditBox) in the screen remains the UITextfield, and it remains until I stop the process.
> Any suggestion?
>
> You should make sure that CCEditBox was destructed.
> […]

I’ve found why I had an EXC_BAD_ACCESS Exception in the call to resignFirstResponder in EAGLView.mm. The problem was that I close the dialog with the CCEditBox in the callback editBoxReturn. Lost of focus and remove must be done in two steps.
Giannandrea

Giannandrea Castaldi wrote:

I’ve found the reason why the CCEditBox wasn’t correctly removed from the screen, in my dialog CCLayer I had redefined the onExit without calling CCLayer:onExit.
Now I’ve anther problem alsways in iOS, If I open my dialog CCLayer and close it without using CCEditBox the dialog and the CCEditBox are removed correctly without problem, if I select the CCEditBox and the keyboard is open there is no way to avoid an EXC_BAD_ACCESS Exception in the call to resignFirstResponder in EAGLView.mm:
>
[…]
>
Any suggestion?
>
Thanks.
>
Giannandrea
>
Giannandrea Castaldi wrote:
> Hi all,
> I tried to change the scene but the UITextField remains in the screen. Setting a breakpoint the retain method of CCEditBox I’ve found out that probably is called once too many.
> I’ve a scene built with a race CCLayer, when the race is terminated I initialize a dialog CCLayer where, in the init of this dialog, I add a CCEditBox. When the init is terminated the retainCount is correctly 2 (1 for the autoreleasepool and 1 for the add in the dialog). The strange behaviour is when I add the dialog CCLayer in the race CCLayer, during the execution of this addChild is called again the retain in the CCEditBox (I think that is not necessary).
> If it can be useful I’ve added a screenshot of the stacktrace of this last call to the retain.
>
> Thanks for the help.
>
> Giannandrea
>
>
>
> James Chen wrote:
> > @ Giannandrea Castaldi
> > > Now I’ve another problem. After I remove my dialog (the CClayer with added the CCLayerColor and the CCEditBox) in the screen remains the UITextfield, and it remains until I stop the process.
> > Any suggestion?
> >
> > You should make sure that CCEditBox was destructed.
> > […]

hi chen?

i tested cceditbox

then a layer that editbox is added is changed scale less than 1.0

back sprite position and clip bound go to hell

do you know solve this problem?

plz help me dude :slight_smile:

Which version? Which platform?
Did you try the latest release today?
K pop wrote:

hi chen?
>
i tested cceditbox
>
then a layer that editbox is added is changed scale less than 1.0
>
back sprite position and clip bound go to hell
>
do you know solve this problem?
>
plz help me dude :slight_smile:

Hi,

When i use getText on an CCEditBox, I get an EXC_BAD_ACCESS in the following function:

const char* CCEditBox::getText(void)
{
if (m_pEditBoxImpl != NULL)
{
return m_pEditBoxImpl~~>getText; // at this line
}
return NULL;
}
Any reason so as to why im getting this? This is the code to create the CCEditBox:
*userameBox = CCEditBox::create,30);
*userameBox~~>setPosition(ccp(winSize.width/2, winSize.height*3/4));
*userameBox~~>setFontColor;
*userameBox~~>setPlaceHolder;
_userameBox~~>setMaxLength;
*userameBox~~>setReturnType;
*userameBox~~>setDelegate;
addChild;@
And to Access the text, this is what I use:
_userameBox~~>getText()

Where did you invoke *_userameBox->getText()* ?

@Nidhi Ajwani
I tested it in the 2.1.2, and it worked ok.

I have created a CCMenuItemLabel in the same layer , the callback of which is

void GameOverLayer::login(CCObject *obj)
{
if (NULL == _userameBox->getText()) {
CCLog(“Nulll”);
return;
}
}

My current version of cocos2dx is

#define COCOS2D_VERSION 0x00020100

Could you provide a demo to reproduce this issue?

Ok something wrong at my end….I just created a new project and this works perfectly fine in there….

I think the problem is cause I tried to modify the extension a little to set the size of the font that is used by the Basic UITextFeild. Is there any way in which we can do that othewise?

Thanks for the time.

So the thing is it works perfectly fine in a new project. I removed all the changes I had made for sending across the font size. But it still crashes in my current project. How do I send it across now?

So I just found this wonderful extension by Mr Chen today, but I’m struggling to get it working. As it stands, my code looks like:

CCSize editBoxSize = CCSizeMake(100, 50);
CCEditBox *player1Name = CCEditBox::create(editBoxSize, CCScale9Sprite::create(“green_edit.png”));
player1Name~~>setPosition);
player1Name~~>setFontColor(ccBLACK);
player1Name~~>setPlaceHolder;
player1Name~~>setMaxLength(12);
player1Name~~>setText);
//player1Name~~>setDelegate(); <——this line is currently failing saying it cannot initialize with an rvalue of my scene.
player1Name->setReturnType(kKeyboardReturnTypeDone);

addChild(player1Name);

The box with the text comes in just fine, but the keyboard never pops up when you click it. Is this because of the delegate issue I’ve marked? What do I need to do to fix it?

Please check whether ExtensionsTest/EditBoxTest works in TestCpp.

Peter Wiggin wrote:

So I just found this wonderful extension by Mr Chen today, but I’m struggling to get it working. As it stands, my code looks like:
>
CCSize editBoxSize = CCSizeMake(100, 50);
CCEditBox *player1Name = CCEditBox::create(editBoxSize, CCScale9Sprite::create(“green_edit.png”));
player1Name~~>setPosition);
player1Name~~>setFontColor(ccBLACK);
player1Name~~>setPlaceHolder;
player1Name~~>setMaxLength(12);
player1Name~~>setText);
//player1Name~~>setDelegate(); <——this line is currently failing saying it cannot initialize with an rvalue of my scene.
player1Name->setReturnType(kKeyboardReturnTypeDone);
>
addChild(player1Name);
>
The box with the text comes in just fine, but the keyboard never pops up when you click it. Is this because of the delegate issue I’ve marked? What do I need to do to fix it?