在cocos2d-x中垂直滚动图像

时间:2014-08-20 12:39:10

标签: c++ xcode cocos2d-x

我有一个图像,我想垂直(上下)滚动该图像。我使用以下代码垂直滚动。但如果我上去,它就会上升。如果我发布触摸它会自动关闭。我希望它停在那里。

CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCLayer *layer = CCLayer::create();
layer->setAnchorPoint(CCPointZero);

CCSprite *spr=CCSprite::create("img.png");
spr->setPosition(ccp(winSize.width*0.5f,winSize.height*0.1f));
layer->setContentSize( CCSizeMake( winSize.widht, winSize.height));
layer->addChild( spr );


CCScrollView *scrollView =    CCScrollView::create(winSize, layer);
scrollView->retain();
scrollView->setContentSize(CCSizeMake(layer->getContentSize().width,layer->getContentSize().height));
scrollView->setDirection( cocos2d::extension::kCCScrollViewDirectionVertical );
scrollView->setPosition( ccp( 0,0 ) );
scrollView->setContainer( layer );

this->addChild(scrollView);
scrollView->setContentOffset( CCPointZero );

1 个答案:

答案 0 :(得分:2)

尝试在代码中添加以下代码:

scrollView->setBounceEnabled(false);

为我工作。我希望它有所帮助。