Cocos2d-x duplicate button action when clicked

875 Views Asked by At

I have create a button action with cocos2d-x but i dont know how it duplicate my action when button clicked

Here is my code for .h

#include "cocos2d.h"
#include "cocos-ext.h"
#include "CocosGUI.h"

USING_NS_CC;
USING_NS_CC_EXT;
using namespace ui;

class LoginScene : public Scene
{
public:
    LoginScene(bool pPortrait=false);
    ~LoginScene();

    virtual void onEnter();
    virtual void onExit();

    virtual void onLogin();
    virtual void onRegister();
protected:
    Layout* m_pLayout;
    Layer* m_pUILayer;
};

and .cpp

#include "LoginScene.h"
#include "cocostudio/CCSSceneReader.h"
#include "cocostudio/CCSGUIReader.h"
#include "cocostudio/CCActionManagerEx.h"
#include <sqlite3.h>
#include "MainScene.h"

LoginScene::LoginScene(bool pPortrait):m_pLayout(NULL),m_pUILayer(NULL)
{
    Scene::init();
}

LoginScene::~LoginScene()
{

}

void LoginScene::onEnter()
{
    Scene::onEnter();

    m_pUILayer=Layer::create();
    m_pUILayer->scheduleUpdate();
    addChild(m_pUILayer);

    //register root from json
    m_pLayout=dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("LoginScene/LoginScene.json"));
    m_pUILayer->addChild(m_pLayout);

    //button initialize
    Button* btnLogin=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnLogin"));
    btnLogin->addTouchEventListener(CC_CALLBACK_0(LoginScene::onLogin,this));

    Button* btnRegister=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnRegister"));
    btnRegister->addTouchEventListener(CC_CALLBACK_0(LoginScene::onRegister, this));
}

void LoginScene::onRegister()
{ 
    CCLOG("checking");
}

void LoginScene::onExit()
{
    m_pUILayer->removeFromParent();

    cocostudio::GUIReader::destroyInstance();
    cocostudio::ActionManagerEx::destroyInstance();
    cocostudio::SceneReader::destroyInstance();

    Scene::onExit();
}

void LoginScene::onLogin()
{

}

And the AppDelegate.cpp

#include "AppDelegate.h"
#include "LoginScene.h"

USING_NS_CC;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() 
{
}

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("My Game");
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    //design Size
    auto screenSize=glview->getFrameSize();
    auto designSize=Size(960,640);
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::EXACT_FIT);

    // create a scene. it's an autorelease object
    auto scene = new LoginScene;
    scene->autorelease();
    // run
    director->runWithScene(scene);

    return true;
}

Can anyone tell me my mistake :( now it duplicates the log :( tks all

0

There are 0 best solutions below