• cocosbuilder中scrollview的使用





    //
    //  Created by sky on 14-8-19.
    #include <iostream>
    #include 
    "cocos2d.h"
    #include 
    "cocos-ext.h"
    USING_NS_CC
    ;
    USING_NS_CC_EXT;

    class DaojuHelpLayer:public CCLayer,
                        public CCNodeLoaderListener,
                        
    public CCBSelectorResolver,
                        
    public CCBMemberVariableAssigner
    {
    private:
        
    CCScrollView *m_pScrollView;
        
    CCControlButton *m_pButton;
        
    void onBackBtnCallback(CCObject *p,CCControlEvent *e);
    public:
        
    static CCScene* createScene();
        
    static CCNode* createDaojuHelpLayer();
        DaojuHelpLayer();
        ~DaojuHelpLayer();
        
        
    CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(DaojuHelpLayer, create);

        
    //节点加载完毕调用
        
    virtual void onNodeLoaded(CCNode * pNode, CCNodeLoader * pNodeLoader);
        
        
    //实现CCBMemberVariableAssigner接口连接变量
        
    virtual bool onAssignCCBMemberVariable(CCObject* pTarget, const char* pMemberVariableName, CCNode* pNode);
        
        
    //实现CCBSelectorResolver接口, 用于连接菜单项
        
    virtual SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, const char* pSelectorName);
        
    //实现CCBSelectorResolver接口, 用于连接CCControl
        
    virtual SEL_CCControlHandler onResolveCCBCCControlSelector(CCObject * pTarget, const char* pSelectorName);
    };

    class CCBReader;

    class DaojuHelpLayerLoader:public CCLayerLoader
    {
    public:
        
    //使用loader创建loader
        CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(DaojuHelpLayerLoader, loader);
    protected:
        
    //调用create方法创建DaojuHelpLayer类对象
        CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(DaojuHelpLayer);
    };


    //
    //  DaojuHelpLayer.cpp
    //
    //  Created by sky on 14-8-19.
    //
    //

    #include "DaojuHelpLayer.h"

    DaojuHelpLayer::DaojuHelpLayer()
    {
        
    }
    DaojuHelpLayer::~DaojuHelpLayer()
    {
        
    }

    CCSceneDaojuHelpLayer::createScene()
    {
        
    CCScene *scene = CCScene::create();
        
        
    CCNodeLoaderLibrary *ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        ccNodeLoaderLibrary -> 
    registerCCNodeLoader("DaojuHelpLayer"DaojuHelpLayerLoader::loader());
        
    cocos2d::extension::CCBReader *reader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
        reader -> 
    autorelease();
        
    CCNode *node = reader->readNodeGraphFromFile("DaojuHelpUI", scene);
        
    CCAssert(node!=NULL"读取失败");
        scene -> 
    addChild(node);
        
        
    return scene;
    }

    CCNodeDaojuHelpLayer::createDaojuHelpLayer()
    {
        
    CCNodeLoaderLibrary *ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
        ccNodeLoaderLibrary -> 
    registerCCNodeLoader("DaojuHelpLayer"DaojuHelpLayerLoader::loader());
        
    cocos2d::extension::CCBReader *reader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
        reader -> 
    autorelease();
        
    CCNode *node = reader->readNodeGraphFromFile("DaojuHelpUI");
        
    CCAssert(node!=NULL"读取失败");
        
    return node;
    }

    void DaojuHelpLayer::onNodeLoaded(cocos2d::CCNode *pNode, cocos2d::extension::CCNodeLoader *pNodeLoader)
    {
        
    CCLog("you will enter the daoju help layer...");
        
    CCLog("tag:%d",m_pScrollView->getTag());
        
    CCLog("maxoffset:%f,%f",m_pScrollView->minContainerOffset().x,m_pScrollView->minContainerOffset().y);
        
    m_pScrollView -> setContentOffset(m_pScrollView->minContainerOffset());
    }

    bool DaojuHelpLayer::onAssignCCBMemberVariable(cocos2d::CCObject *pTarget, const char *pMemberVariableName, cocos2d::CCNode *pNode)
    {
    //    CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mScrollView", CCScrollView*, this->m_pScrollView);
        CCB_MEMBERVARIABLEASSIGNER_GLUE(
    this"backBtn", CCControlButton*, this->m_pButton);
        CCB_MEMBERVARIABLEASSIGNER_GLUE_WEAK(
    this"mScrollView", CCScrollView*, this->m_pScrollView);
        
    return false;
    }

    SEL_MenuHandler DaojuHelpLayer::onResolveCCBCCMenuItemSelector(cocos2d::CCObject *pTarget, 
    const char *pSelectorName)
    {
        
    return NULL;
    }

    SEL_CCControlHandler DaojuHelpLayer::onResolveCCBCCControlSelector(cocos2d::CCObject *pTarget, 
    const char *pSelectorName)
    {
        
    CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this"backToMain"DaojuHelpLayer::onBackBtnCallback);
        
        
    return NULL;
    }

    void DaojuHelpLayer::onBackBtnCallback(cocos2d::CCObject *p, CCControlEvent *e)
    {
        
    CCLog("backBtn callback...");
    }



  • 相关阅读:
    Oracle 过滤和排序数据
    Oracle基础知识介绍
    禁用笔记本自带的键盘
    阿里云服务开启swap分区。
    谷粒商城nacos远程配置中心出错
    nacos修改密码
    ssm+maven+json 依赖版本
    idea 使用maven创建web过慢解决问题
    mybatis的动态sql
    mybatis -基础知识点梳理
  • 原文地址:https://www.cnblogs.com/skyxu123/p/9543821.html
Copyright © 2020-2023  润新知