我已经使用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