欢迎光临Software MyZone,有问题可留言或到站点论坛发帖,争取第一时间帮忙解决 || 站点论坛:火龙论坛 || 淘宝小店:应小心的易淘屋 【欢迎大家提建设性意见】

如何使用Cocosbuilder

本文为firedragonpzy原创,转载务必在明显处注明:
转载自【Softeware MyZone】原文链接:
http://www.firedragonpzy.com.cn/index.php/archives/3913

欢迎热爱编程的朋友们参与到cocos2d-x编程中,为了给大家提供良好的交流环境,网站以开启QQ群
Software MyZone:66202765(群号,欢迎加入,若满,请加1群)
Software MyZone 1群(2dx):286504621
【加群请写:Software MyZone或者是firedragonpzy】
淘宝店:【应小心的易淘屋】初次开店,大家多多支持……
群论坛:火龙论坛正试运营阶段,欢迎大家多提些建设性意见……

之前用了ccbi,感觉还可以,看现在越来越多的人使用了,所以和大家分享一下之前的些许方法,同时提供给新手如何入门的方法。

关于新手:
1)最近本的使用

//
//  BigLevelCksLayer.h
//  CKCastle
//
//  Created by firedragonpzy on 13-1-16.
//
//

#ifndef __CKCastle__BigLevelCksLayer__
#define __CKCastle__BigLevelCksLayer__

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

USING_NS_CC;
using namespace extension;

class BigLevelCksLayer : public CCLayer
{
public:
    
    void onExit();
    CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(BigLevelCksLayer, create);
};

class BigLevelCksLayerLoader : public CCLayerLoader
{
public:
    CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(BigLevelCksLayerLoader, loader);
protected:
    CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(BigLevelCksLayer);
};

#endif /* defined(__CKCastle__BigLevelCksLayer__) */

2)监听节点加载:
继承CCNodeLoaderListener,同时实现

virtual void onNodeLoaded(CCNode * pNode, CCNodeLoader * pNodeLoader);

3)监听按钮、菜单
继承CCBSelectorResolver,同时实现

virtual SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName);

virtual extension::SEL_CCControlHandler onResolveCCBCCControlSelector(CCObject * pTarget, CCString * pSelectorName);

针对简洁:

static CCScene* getSceneByCCBI( const char * pClassName, CCNodeLoader *pCCNodeLoader, const char *pCCBFileName)
    {
        CCNodeLoaderLibrary *nodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        nodeLoaderLibrary->registerCCNodeLoader(pClassName,pCCNodeLoader);
        CCBReader *ccbReader = new CCBReader(nodeLoaderLibrary);
        ccbReader->autorelease();
        CCScene *pScene = ccbReader->createSceneWithNodeGraphFromFile(pCCBFileName);
        return pScene;
    }
    
    static CCScene* getSceneAndLayerByCCBI( const char * pClassName, CCNodeLoader *pCCNodeLoader, const char *pCCBFileName,const char * pClassName1, CCNodeLoader *pCCNodeLoader1, const char *pCCBFileName1  )
    {
        CCNodeLoaderLibrary *nodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        nodeLoaderLibrary->registerCCNodeLoader(pClassName,pCCNodeLoader);
        nodeLoaderLibrary->registerCCNodeLoader(pClassName1,pCCNodeLoader1);
        CCBReader *ccbReader = new CCBReader(nodeLoaderLibrary);
        ccbReader->autorelease();
        CCScene *pScene = ccbReader->createSceneWithNodeGraphFromFile(pCCBFileName);
        CCBReader *ccbReader1 = new CCBReader(nodeLoaderLibrary);
        ccbReader1->autorelease();
        CCLayer *layer = (CCLayer*)ccbReader1->readNodeGraphFromFile(pCCBFileName1);
        CCPoint point = CCDirector::sharedDirector()->getVisibleOrigin();
        layer->setPosition(ccp( point.x, point.y));
        pScene->addChild(layer,1);
        return pScene;
    }
    static CCScene* getSceneAndLayerWithSVByCCBI( const char * pClassName, CCNodeLoader *pCCNodeLoader, const char *pCCBFileName,const char * pClassName1, CCNodeLoader *pCCNodeLoader1, const char *pCCBFileName1, const char * pClassName2,CCNodeLoader *pCCNodeLoader2 )
    { 
        CCNodeLoaderLibrary *nodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        nodeLoaderLibrary->registerCCNodeLoader(pClassName,pCCNodeLoader);
        nodeLoaderLibrary->registerCCNodeLoader(pClassName2,pCCNodeLoader2);
        CCBReader *ccbReader = new CCBReader(nodeLoaderLibrary);
                nodeLoaderLibrary->registerCCNodeLoader(pClassName1,pCCNodeLoader1);
        ccbReader->autorelease();
        CCScene *pScene = ccbReader->createSceneWithNodeGraphFromFile(pCCBFileName);
        CCBReader *ccbReader1 = new CCBReader(nodeLoaderLibrary);
        ccbReader1->autorelease();
        CCLayer *layer = (CCLayer*)ccbReader1->readNodeGraphFromFile(pCCBFileName1);
        CCPoint point = CCDirector::sharedDirector()->getVisibleOrigin();
        layer->setPosition(ccp( point.x, point.y));
        pScene->addChild(layer,1);
        return pScene;
    }

简单使用:

1)getSceneByCCBI(…)

CCScene *pScene =  UtilTools::getSceneByCCBI(CCBI_MAINMENU_SCENE, MainMenuSceneLoader::loader(), CCBI_MAINMENU_SCENE_FILE);

2)getSceneAndLayerByCCBI(…)

CCScene *pScene = UtilTools::getSceneAndLayerByCCBI(CCBI_BIGLEVEL_SCENE, BigLevelSceneLoader::loader(),CCBI_BIGLEVEL_SCENE_FILE,CCBI_BIGLEVELCKS_LAYER,BigLevelCksLayerLoader::loader(),CCBI_BIGLEVELCKS_LAYER_FILE);
    CCDirector::sharedDirector()->replaceScene(pScene);

3getSceneAndLayerWithSVByCCBI(…)

CCScene *pScene = UtilTools::getSceneAndLayerWithSVByCCBI(CCBI_LITTLELEVEL_SCENE, LittleLevelSceneLoader::loader(), CCBI_LITTLELEVEL_SCENE_FILE, CCBI_BIGLEVELCKS_LAYER, BigLevelCksLayerLoader::loader(), CCBI_BIGLEVELCKS_LAYER_FILE, CCBI_LITTLELEVEL_MENU_LAYER,MenuLoader::loader());
    CCDirector::sharedDirector()->replaceScene(pScene);

简单就这些吧,后续补充……

发表评论