A page view is similar to a scroll view, but it will be scrolled on a page-by-page basis. PageView
is also a class in Cocos2d-x. In this recipe, we will explain how to use the PageView
class.
Let's immediately get it implemented. Here, we will arrange three images of HelloWorld.png
side-by-side in the page view. Create the page view by using the following code:
auto pageView = ui::PageView::create(); pageView->setPosition(Vec2()); pageView->setContentSize(size); this->addChild(pageView); for (int i=0; i<3; i++) { auto page = ui::Layout::create(); page->setContentSize(pageView->getContentSize()); auto sprite = Sprite::create("res/HelloWorld.png"); sprite->setPosition(sprite->getContentSize()/2); page->addChild(sprite); pageView->insertPage(page, i); } pageView->addEventListener([](Ref* sender, ui::PageView::EventType type){ if (type==ui::PageView::EventType::TURNING) { auto pageView =...