Cocos2d-x ScrollView使用

前端之家收集整理的这篇文章主要介绍了Cocos2d-x ScrollView使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Size size = Director::getInstance()->getVisibleSize();
cocos2d::ui::ScrollView* sView = cocos2d::ui::ScrollView::create();
sView->setContentSize(Size(500,400));
//sView->setDirection(ui::ScrollView::Direction::HORIZONTAL);//可以设置横向滑动
sView->setBackGroundImage("ccicon.png");
sView->setAnchorPoint(Point(0.5f,0.5f));
sView->setPosition(Vec2(size.width /2,size.height/2));
sView->setRotation(45);//45度滑动
this->addChild(sView);


ImageView* imageView = ImageView::create("ccicon.png");
float innerWidth = sView->getContentSize().width;
float innerHeight = sView->getContentSize().height + 200;


sView->setInnerContainerSize(Size(innerWidth,innerHeight));//方法设置包含内容的区域大小,在拖动的过程中,边界检查
Button* button = Button::create("animationbuttonnormal.png","animationbuttonpressed.png");
button->setPosition(Vec2(innerWidth / 2.0f,sView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
sView->addChild(button);


Button* titleButton = Button::create("backtotopnormal.png","backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Vec2(innerWidth / 2.0f,button->getBottomBoundary() - button->getContentSize().height));
sView->addChild(titleButton);


Button* button_scale9 = Button::create("button.png","buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f,button_scale9->getVirtualRendererSize().height));
button_scale9->setPosition(Vec2(innerWidth / 2.0f,titleButton->getBottomBoundary() - titleButton->getContentSize().height));
sView->addChild(button_scale9);


imageView->setPosition(Vec2(innerWidth / 2.0f,imageView->getContentSize().height / 2.0f));
sView->addChild(imageView);


//Size size = Director::getInstance()->getVisibleSize();
ui::ScrollView* scrollView = ui::ScrollView::create();
scrollView->setDirection(ui::ScrollView::Direction::BOTH);
scrollView->setTouchEnabled(true);
scrollView->setBounceEnabled(true);
scrollView->setBackGroundImageScale9Enabled(true);
scrollView->setBackGroundImage("green_edit.png");
scrollView->setContentSize(Size(210,122.5));
scrollView->setAnchorPoint(Point(0.5f,0.5f));
scrollView->setPosition(Vec2(size.width /2,size.height /2));
ImageView* imageView2 = ImageView::create("Hello.png");
scrollView->addChild(imageView2);


scrollView->setInnerContainerSize(imageView2->getContentSize());
scrollView->scrollToPercentBothDirection(Vec2(50,50),2,true);//设置滑动到指定位置 (50,50)为到中心位置 Size innerSize = scrollView->getInnerContainerSize(); imageView2->setPosition(Vec2(innerSize.width / 2.0f,innerSize.height / 2.0f)); sView->addChild(scrollView);

猜你在找的Cocos2d-x相关文章