首页 > 其他 > 详细

加载翻页容器并添加简单交互的功能

时间:2015-11-15 06:13:30      阅读:852      评论:0      收藏:0      [点我收藏+]

1.用cocos studio创建一个关卡选择的示例工程。

技术分享

 

 

 

 

 

 

 

 

 

 

 

2.用cocos studio创建一个所有资源的和图(.plist)。

技术分享

3.用IDE打开工程。

4.接着看代码。

Director::getInstance()->getTextureCache()->addImageAsync("Plist.png", [this](Texture2D* texture){
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Plist.plist", texture);
    log("done");
    auto rootNode = CSLoader::createNode("MainScene.csb");
    addChild(rootNode);

    auto layer = rootNode->getChildByName<Layer*>("ProjectNode_1");
    auto pageView = layer->getChildByName<ui::PageView*>("PageView_SelectPage");
    auto leftButton = layer->getChildByName<ui::Button*>("Button_Left");
    auto rightButton = layer->getChildByName<ui::Button*>("Button_Right");

    auto layout = layer->getChildByName<ui::Layout*>("Panel_7");
    auto levelNumber = layout->getChildByName<ui::TextAtlas*>("LabelAtlas_CurrentScene");

    pageView->addEventListener([levelNumber, pageView](Ref* ref, ui::PageView::EventType type){
        if (type == ui::PageView::EventType::TURNING){
            levelNumber->setString(StringUtils::format("%d/3", pageView->getCurPageIndex() + 1));
        }
    });

    leftButton->addClickEventListener([pageView](Ref* ref){
        auto index = pageView->getCurPageIndex();
        index--;
        if (index < 0){
            return;
        }
        pageView->scrollToPage(index);
    });

    rightButton->addClickEventListener([pageView](Ref* ref){
        auto index = pageView->getCurPageIndex();
        index++;
        if (index > 2){
            return;
        }
        pageView->scrollToPage(index);
    });

});

log("loding");

 

加载翻页容器并添加简单交互的功能

原文:http://www.cnblogs.com/StuLiuJun/p/4966055.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!