【发布时间】:2015-06-17 23:04:16
【问题描述】:
想知道是否有人知道如何在 cocos2d-x 3.6 (C++) 中实现滚动视图。我找到的所有教程都是针对早期 cocos2d-x 版本的。
谢谢
我在下面添加了我的代码,我可以显示灰色的滚动视图框,但它不能滚动并且按钮没有出现在上面:
头文件:“CocosGUI.h”和“cocos-ext.h”
//add scroll view
Size scollFrameSize = Size(visibleSize.width, visibleSize.height/4);
auto scrollView = cocos2d::ui::ScrollView::create();
scrollView->setContentSize(scollFrameSize);
scrollView->setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID);
scrollView->setBackGroundColor(Color3B(200, 200, 200));
scrollView->setPosition(Point(0, visibleSize.height/1.5));
scrollView->setDirection(cocos2d::ui::ScrollView::Direction::HORIZONTAL);
scrollView->setBounceEnabled(true);
scrollView->setTouchEnabled(true);
auto containerSize = Size(scollFrameSize.width*2, scollFrameSize.height*2);
scrollView->setInnerContainerSize(containerSize);
this->addChild(scrollView);
auto button1 = cocos2d::ui::Button::create();
button1->setColor(Color3B(250, 200, 50));
button1->setTouchEnabled(true);
button1->setContentSize(Size(100, 100));
button1->setPosition(Point(containerSize.width / 4, containerSize.height / 2));
scrollView->addChild(button1);
auto button2 = cocos2d::ui::Button::create();
button2->setColor(Color3B(250, 200, 50));
button1->setContentSize(Size(100, 100));
button2->setTouchEnabled(true);
button2->setPosition(Point(containerSize.width / 8, containerSize.height / 2));
scrollView->addChild(button2);
【问题讨论】: