码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-x3.0 PageView

时间:2014-04-30 22:31:39      阅读:405      评论:0      收藏:0      [点我收藏+]

标签:cocos2d-x   layout   ui   pageview   pagevieweventselecto   


.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;
    }
}
mamicode.com,码迷

cocos2d-x3.0 PageView

标签:cocos2d-x   layout   ui   pageview   pagevieweventselecto   

原文地址:http://blog.csdn.net/qqmcy/article/details/24800395

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!