cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.2k stars 7.06k forks source link

ui::EditBox Android background/foreground issue. #14982

Open hgokturk opened 8 years ago

hgokturk commented 8 years ago

I realized that after going to background in Android and coming back to foreground, EditBox doesn't show any characters previously entered but keeps them somehow. And it is not touchable.

zilongshanren commented 8 years ago

@hgokturk What's the version of your cocos2d-x?

Could I reproduce this issue 100%?

hgokturk commented 8 years ago

It happens both for 3.8 & 3.10. I'm sure it is reproducable. I can share editbox initialization codes and my appdelegate or anything else if needed.

zilongshanren commented 8 years ago

@hgokturk please show me the code...

hgokturk commented 8 years ago

AppDelegate.h

void AppDelegate::applicationDidEnterBackground() {
    Director::getInstance()->stopAnimation();
}

void AppDelegate::applicationWillEnterForeground() {
    Director::getInstance()->startAnimation();
}

LoginRegisterScene.h

#pragma once

#include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "extensions/cocos-ext.h"

class LoginRegisterScene : public cocos2d::Layer, public cocos2d::extension::EditBoxDelegate
{
public:
    static cocos2d::Scene* createScene();

    virtual bool init();

    CREATE_FUNC(LoginRegisterScene);

    void Login(cocos2d::Ref *sender);

    virtual void editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox);
    virtual void editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox);
    virtual void editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text);
    virtual void editBoxReturn(cocos2d::ui::EditBox* editBox);
private:
    ...............................
    cocos2d::ui::EditBox* username;
    cocos2d::ui::EditBox* email;
    cocos2d::ui::EditBox* password;
    ...............................
};

Sample init in LoginRegisterScene.cpp

this->username = ui::EditBox::create(Size(320 / Director::getInstance()->getContentScaleFactor(), 70 / Director::getInstance()->getContentScaleFactor()), ui::Scale9Sprite::create(pNormalSprite));
//this->username->setPosition(Vec2(visibleSize.width * 66 / 100 + origin.x, visibleSize.height * 63 / 100 + origin.y));
this->username->setPosition(Vec2(bgSprite->getContentSize().width * 66 / 100, bgSprite->getContentSize().height * 63 / 100));
this->username->setFontName("AmericanTypewriter");
this->username->setFontSize(13);
this->username->setFontColor(Color3B::BLACK);
//username->setPlaceHolder("Kullanıcı Adı:");
this->username->setPlaceholderFontColor(Color3B::WHITE);
this->username->setInputFlag(ui::EditBox::InputFlag::INITIAL_CAPS_WORD);
this->username->setInputMode(ui::EditBox::InputMode::SINGLE_LINE);
this->username->setMaxLength(15);
this->username->setReturnType(ui::EditBox::KeyboardReturnType::DONE);
this->username->setDelegate(this);
this->username->setTag(50);
bgSprite->addChild(this->username, 5);

And the listeners in LoginRegisterScene.cpp

void LoginRegisterScene::editBoxEditingDidBegin(ui::EditBox* editBox)
{
    log("editBox %p DidBegin !", editBox);
}

void LoginRegisterScene::editBoxEditingDidEnd(ui::EditBox* editBox)
{
    log("editBox %p DidEnd !", editBox);
}

void LoginRegisterScene::editBoxTextChanged(ui::EditBox* editBox, const std::string& text)
{
    switch(editBox->getTag()){
    case 50:
        this->txtUsername = text.c_str();
        log("username: %s", this->txtUsername.c_str());
        break;
    case 100:
        this->txtPassword = text.c_str();
        log("password: %s", this->txtPassword.c_str());
        break;
    case 150:
        this->txtEmail = text.c_str();
        log("email: %s", this->txtEmail.c_str());
        break;
    }
}

void LoginRegisterScene::editBoxReturn(ui::EditBox* editBox)
{
    log("editBox %p was returned !",editBox);
}
hgokturk commented 8 years ago

I wonder if it's about using #parma once instead #ifndef

zilongshanren commented 8 years ago

@hgokturk Could you make a minimal demo project and send it to me? Thanks.

pabitrapadhy commented 8 years ago

any fix for this found, it seems like, I am also facing the same issue. but for me it happens in iOS as well. in v3.9

zilongshanren commented 8 years ago

@pabitrapadhy Could I reproduce this issue with cpp-tests? thanks