01.bool HelloWorld::init()
02.{
03.//首先创建scrollView
04.auto scroll_layer = Layer::create();//创建scrollView中的容器层
05.scroll_layer->setPosition(Point::ZERO);
06.scroll_layer->setAnchorPoint(Point::ZERO);
07.scroll_layer->setContentSize(Size(600,300));//设置容器层大小为(600,300)
08.
09.auto scrollView = ScrollView::create(Size(400,300),scroll_layer);//创建scrollView,显示窗口大小为(400,300)
10.scrollView->setDelegate(this);//设置委托
11.scrollView->setDirection(ScrollView::Direction::HORIZONTAL);//设置滚动方向为水平
12.scrollView->setPosition(Point(300,200));
13.this->addChild(scrollView,2);
14.
15.//创建三个对象
16.auto boy = Sprite::create("boy.png");//没错,主角又是我们熟悉的那仨。多么温馨。
17.boy->setPosition(Point(150,100));
18.scroll_layer->addChild(boy,2);
19.
20.auto girl = Sprite::create("girl_1.png");
21.girl->setPosition(Point(300,100));
22.scroll_layer->addChild(girl,2);
23.
24.auto girl3 = Sprite::create("girl_3.png");
25.girl3->setPosition(Point(450,100));
26.scroll_layer->addChild(girl3,2);
27.
28.sp_vec.pushBack(boy);//将三个对象放入容器中
29.sp_vec.pushBack(girl);
30.sp_vec.pushBack(girl3);
31.
32.return true;
33.}