1

How can I add items to cocos 2dx scroll view ? The following code is for creating the scrollview.

      _scrollView = cocos2d::extension::CCScrollView::create(CCSizeMake(posW, 1000));
        _scrollView->setPosition(posX, posY);
        _scrollView->setDirection(cocos2d::extension::kCCScrollViewDirectionVertical);

        _scrollView->setVisible(true);

I don't know how to proceed further. Please help.

Thanks in advance

3
  • setContentNode perhaps? The content node contains all the child nodes you need in the scrollview
    – CodeSmile
    May 22, 2014 at 6:07
  • the real problem is I don't know how to add items to setContentNode. :) I modified the code as below cocos2d::CCNode *pContainer = new CCNode(); _scrollView->setContainer(pContainer); Nothing is showing. Please provide me one sample code
    – charlotte
    May 22, 2014 at 6:13
  • the ccnode itself does not draw anything, try adding a sprite to pContainer
    – CodeSmile
    May 22, 2014 at 6:18

1 Answer 1

1
_scrollView->addChild(yourNode);

This automatically places the nodes in the scroll views container because scroll view overrides the addChild method from node.

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.