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

Cocos2d-X加载UI Editor

时间:2014-11-11 02:00:12      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   os   sp   div   on   

Layer* uiLayer = Layer::create();
    myLayout = dynamic_cast<ui::Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("enter/enter_1.json"));
    uiLayer->addChild(myLayout);
    uiLayer->setPosition(250, 400);
    sprite->addChild(uiLayer, 12);

1.加载进度条

HelloScene.cpp

loadingBar = dynamic_cast<LoadingBar*>(myLayout->getChildByTag(1));
    loadingBar->setPercent(0);
    this->schedule(schedule_selector(HelloWorld::runningSchedule));

进度条回调

void HelloWorld::runningSchedule(float dt)
{
    int prc = loadingBar->getPercent() + 1;
    if (prc == 100)
    {
        auto reScene  = TransitionCrossFade::create(1.0, GameLogin::createScene());//当进度条满时进入下一场景
        Director::getInstance()->setDepthTest(false);
        Director::getInstance()->replaceScene(reScene);
    }
    loadingBar->setPercent(prc);
}

 2.加载按钮

Button* startBtn = dynamic_cast<Button*>(myLayout->getChildByTag(4)->getChildByTag(69));
    startBtn->addTouchEventListener(this, toucheventselector(GameLogin::touchButton));

按钮回调

void HelloWorld::touchButton(Object* obj, TouchEventType eventType){
    auto button = dynamic_cast<Button*>(obj);
    int tag = button->getTag();
    switch (eventType)
    {
    case TouchEventType::TOUCH_EVENT_BEGAN:
        break;
    }
}

 

Cocos2d-X加载UI Editor

标签:style   blog   io   color   ar   os   sp   div   on   

原文地址:http://www.cnblogs.com/Susake/p/4088593.html

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