0

我已经用 cocos2d-x 创建了一个按钮操作,但我不知道当按钮单击时它是如何复制我的操作的

这是我的 .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;
};

和.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()
{

}

和 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;
}

谁能告诉我我的错误:(现在它复制了日志:(tks all

4

0 回答 0