cocos2d-x3.0 PageView

Posted cynchanpin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cocos2d-x3.0 PageView相关的知识,希望对你有一定的参考价值。


.h加入例如以下代码:

    void pageViewEvent(Ref *pSender, PageViewEventType type);


.m

   layout = Layout::create();
        layout->setSize(Size(widgetSize.width, widgetSize.height));
       
        //横向排列,这里相似android里的线性布局
        //layout->setLayoutType(LAYOUT_RELATIVE);
        /*以图片为背景*/
        layout->setBackGroundImageScale9Enabled(true);
        layout->setBackGroundImage("green_edit.png");
        
        layout->setPosition(Point(0,0));
        addChild(layout);

        /******************************************************************************************/
        PageView* pageView = PageView::create();
        pageView->setSize(Size(480, 260));
        pageView->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2));
        
        for (int i = 0; i < 3; i++) {
            Layout* layout1 = Layout::create();
            layout1->setSize(Size(480, 260));
            
            ImageView* imageView = ImageView::create("scrollviewbg.png");
            imageView->setScale9Enabled(true);
            imageView->setSize(Size(480, 260));
            imageView->setPosition(Point(layout1->getSize().width / 2, layout1->getSize().height / 2));
            layout1->addChild(imageView);
            
            
            
            Text* label = Text::create(StringUtils::format("page %d",(i+1)), "fonts/Marker Felt.ttf", 30);
            label->setColor(Color3B(92, 192, 192));
            label->setPosition(Point(layout1->getSize().width / 2.0f, layout1->getSize().height / 2.0f));
            layout1->addChild(label);
            
            
            
            pageView->addPage(layout1);
            
            
            

        }
       
        pageView->addEventListenerPageView(this, pagevieweventselector(LayoutTest::pageViewEvent));
        
        layout->addChild(pageView);

void LayoutTest::pageViewEvent(cocos2d::Ref *pSender, PageViewEventType type)
{
    switch (type) {
        case cocos2d::ui::PAGEVIEW_EVENT_TURNING:
        {
            PageView* pageView = dynamic_cast<PageView*>(pSender);
            log("%d",pageView->getCurPageIndex() + 1);
        }
            break;
            
        
        default:
            break;
    }
}
技术分享







以上是关于cocos2d-x3.0 PageView的主要内容,如果未能解决你的问题,请参考以下文章

(27)Cocos2d-x 3.0 Json用法

cocos2d-x 3.0 内存管理机制

cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第一步---開始界面&amp;关卡选择

Android - 新的 BottomNavigationBar 中的 PageView - 防止重新加载片段

Cocos2d-x3.0 从代码中获取cocostudio编辑的UI控件

cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第三步---编辑器---更方便很多其它操作更像编辑器