初始cocoStudio(一)并生成文件加载到项目运用

前端之家收集整理的这篇文章主要介绍了初始cocoStudio(一)并生成文件加载到项目运用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

文件目录:


登录界面:


注册界面:


将cocoStudio导出的文件放到项目的Resource里面,.h文件代码如下:

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "cocos-ext.h"
USING_NS_CC;
USING_NS_CC_EXT;
using namespace gui;


class HelloWorld : public cocos2d::CCLayer
{
public:
 
    virtual bool init();  
    static cocos2d::CCScene* scene();
    void menuCloseCallback(CCObject* pSender);
    CREATE_FUNC(HelloWorld);
	
	void OnloginFunc(CCObject* pSender,TouchEventType tType);
	void OnregisterFunc(CCObject* pSender,TouchEventType tType);
	void OnexitFunc(CCObject* pSender,TouchEventType tType);
	void OnregisterTwoFunc(CCObject* pSender,TouchEventType tType);
	void OnexitTwoFunc(CCObject* pSender,TouchEventType tType);

private:
	UILayer*			m_mainLayer; 
	UIPanel *			m_PanelOfLogin;
	UIPanel *			m_PanelOfRegister;
};

#endif // __HELLOWORLD_SCENE_H__

然后,.cpp文件里面的内容

#include "HelloWorldScene.h"

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    HelloWorld *m_mainLayer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(m_mainLayer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

	
	m_mainLayer = UILayer::create();
    UILayout * layout = dynamic_cast<UILayout *>(GUIReader::shareReader()->widgetFromJsonFile("20121215-01_1.json"));
	if (layout != NULL)
	{
		m_mainLayer->addWidget(layout);
	}
	m_mainLayer->setPosition(CCPointZero);
	this->addChild(m_mainLayer);

	m_PanelOfLogin = dynamic_cast<UIPanel *>(m_mainLayer->getWidgetByName("loginPanel"));
	m_PanelOfRegister = dynamic_cast<UIPanel *>(m_mainLayer->getWidgetByName("registerPanel"));
	m_PanelOfRegister->setEnabled(false);
	
	UIButton * loginBt = dynamic_cast<UIButton *>(m_mainLayer->getWidgetByName("Login_Button"));
	loginBt->addTouchEventListener(this,toucheventselector(HelloWorld::OnloginFunc));
	UIButton * registerBtn = dynamic_cast<UIButton *>(m_mainLayer->getWidgetByName("registerBtn"));
	registerBtn->addTouchEventListener(this,toucheventselector(HelloWorld::OnregisterFunc));	
	UIButton * exitBtn = dynamic_cast<UIButton *>(m_mainLayer->getWidgetByName("exitBtn"));
	exitBtn->addTouchEventListener(this,toucheventselector(HelloWorld::OnexitFunc));

	UIButton * registerTwo = dynamic_cast<UIButton *>(m_mainLayer->getWidgetByName("register"));
	registerTwo->addTouchEventListener(this,toucheventselector(HelloWorld::OnregisterTwoFunc));
	UIButton * exitTwo = dynamic_cast<UIButton *>(m_mainLayer->getWidgetByName("exit"));
	exitTwo->addTouchEventListener(this,toucheventselector(HelloWorld::OnexitTwoFunc));

    return true;
}
void HelloWorld::OnloginFunc(CCObject* pSender,TouchEventType tType)
{
	CCLOG("Login");
}
void HelloWorld::OnregisterFunc(CCObject* pSender,TouchEventType tType)
{
	CCLOG("register");	
	m_PanelOfRegister->setEnabled(true);
	m_PanelOfLogin->setEnabled(false);
}
void HelloWorld::OnexitFunc(CCObject* pSender,TouchEventType tType)
{
	CCLOG("exit");
	CCDirector::sharedDirector()->end();
}
void HelloWorld::OnregisterTwoFunc(CCObject* pSender,TouchEventType tType)
{
	CCLOG("register  Completely!!!");
	CCLOG("Send userdata to service");
}
void HelloWorld::OnexitTwoFunc(CCObject* pSender,TouchEventType tType)
{
	CCLOG("exitTwo");
	m_PanelOfRegister->setEnabled(false);
	m_PanelOfLogin->setEnabled(true);
}
具体功能是,点击注册进入注册,填写信息后,退出登录登录界面有退出功能很简单。

猜你在找的Cocos2d-x相关文章