Cocos2d-x_CCSrollView(滚动视图类)介绍

Cocos2d-x_CCSrollView(滚动视图类)介绍,第1张

概述//// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d:
//// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::cclayer,public extension::CCScrollVIEwDelegate  //CCScrollVIEwDelegate{public:    virtual bool init();    static cocos2d::CCScene* scene();    CREATE_FUNC(HelloWorld);        // 必须重写和定义CCScrollVIEwDelegate的协议,要不然CREATE_FUNC宏会报错    virtual voID scrollVIEwDIDScroll(CCScrollVIEw* vIEw);    virtual voID scrollVIEwDIDZoom(CCScrollVIEw* vIEw);};#endif

//// HelloWorldScene.cpp//#include "HelloWorldScene.h"USING_NS_CC;CCScene* HelloWorld::scene(){    CCScene *scene = CCScene::create();    HelloWorld *layer = HelloWorld::create();    scene->addChild(layer);    return scene;}bool HelloWorld::init(){    if ( !cclayer::init() )    {        return false;    }    CCSize winSize = CCDirector::sharedDirector()->getWinSize();    // 创建一个layer作为容器    cclayer *containLayer = cclayer::create();        CCSprite *pSpr1 = CCSprite::create("HelloWorld.png");    pSpr1->setposition(ccp(winSize.wIDth*0.5,winSize.height*0.5));        CCSprite *pSpr2 = CCSprite::create("HelloWorld.png");    pSpr2->setposition(ccp(pSpr1->getContentSize().wIDth,winSize.height*0.5));        containLayer->addChild(pSpr1);    containLayer->addChild(pSpr2);    containLayer->setContentSize(CCSizeMake(winSize.wIDth*3,winSize.height));        // 创建CCScrollVIEw    CCScrollVIEw *pScrVIEw = CCScrollVIEw::create(CCSizeMake(winSize.wIDth*2,winSize.height));    pScrVIEw->setBounceable(false);    pScrVIEw->setContainer(containLayer);        // 必须在AppController.mm中开启ios对多触点的支持    //[__glVIEw setMultipletouchEnabled:YES];    pScrVIEw->settouchEnabled(true);    pScrVIEw->setDelegate(this);    this->addChild(pScrVIEw);        return true;}voID HelloWorld::scrollVIEwDIDScroll(cocos2d::extension::CCScrollVIEw *vIEw){    cclog("scrVIEw移动");}voID HelloWorld::scrollVIEwDIDZoom(cocos2d::extension::CCScrollVIEw *vIEw){    cclog("scrVIEw缩放");}
</pre><pre name="code" >
总结

以上是内存溢出为你收集整理的Cocos2d-x_CCSrollView(滚动视图类)介绍全部内容,希望文章能够帮你解决Cocos2d-x_CCSrollView(滚动视图类)介绍所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1004655.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存