1

I am working on Android game application and need to scroll cclayer horizontally. I have main activity and have multiple layers added on main Activity. I am not getting how to use CCScroller or scrollview in cclayer android cocos2dx

2 Answers 2

0

You can create a scrollview like the following:

CCScrollView *scrollView = CCScrollView::create(CCSizeMake(200, 120));
scrollView->setContentSize(CCSizeMake(400, 120));
scrollView->setPosition(CCPointZero);
scrollView->setDirection(kCCScrollViewDirectionHorizontal);
this->addChild(scrollView);

An then you can add sub layers into it like:

CCLayerColor *layerColor = CCLayerColor::create(ccc4(255, 0, 0, 155), 200, 120);
layerColor->setPosition(ccp(0,0));
scrollView->addChild(layerColor);

CCLayer *layerColor = CCLayerColor::create(ccc4(0, 255, 0, 155), 200, 120);
layerColor->setPosition(ccp(200,0));
scrollView->addChild(layerColor);

Hope this helps!

2
  • 1
    Do you have any idea, where can i find CCScrollView class?
    – dg_no_9
    Jan 6, 2014 at 11:06
  • Refer: cocos2dx/extensions/GUI/CCScrollView/CCScrollView.cpp
    – Zangetsu
    Jan 31, 2014 at 22:41
0

If you can't find ScrollView class, you should add 2 line:

#include "cocos-ext.h"

using namespace cocos2d::extension;

Hope this help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.