Haroon
Haroon

Reputation: 695

Adding UIScrollView To CCSprite

I want to add a UIScrollView To CCSprite because i want to manage the z value and scroll view is on top always.

I have implemented that by adding to [[CCDirector sharedDirector]view] but as you know it goes all over the top and I don't want that. please help me out If somebody knows how to do that.

Upvotes: 1

Views: 167

Answers (1)

KARTHIK  RA
KARTHIK RA

Reputation: 469

   try this code (cocos2dx)

CCSprite *sprite;
ScrollView= CCScrollView::create(CCSizeMake(mWidth,mHeight));
ScrollView->setDirection(kCCScrollViewDirectionVertical);

CCLayer* messageLayer = CCLayer::create();
messageLayer->addChild(sprite,1);

messageLayer->setContentSize(CCSizeMake(mWidth, maxContentHeight));
float offsetY = mHeight - messageLayer->boundingBox().size.height;
ScrollView->setContainer(messageLayer);
ScrollView->setContentOffset(ccp(0, offsetY));

ScrollView->updateInset();
ScrollView->setPosition(ccp(0,mHeight/6));
this->addChild(ScrollView);

Upvotes: 1

Related Questions