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

Cocos2d-x3.0 LoadingBar

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

标签:cocos2d-x   extension   loadingbar   

.h中添加

    
    int _count;
    Layout* layout;
    void update(float delta);






  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);

        
       
        LoadingBar* loadingBar = LoadingBar::create("slider_bar_active_9patch.png");
        loadingBar->setTag(0);
        loadingBar->setScale9Enabled(true);
        loadingBar->setCapInsets(Rect(0, 0, 0, 0));
        loadingBar->setSize(Size(300, 23));
        
        
        //设置加载方向LoadingBarTypeRight右    LoadingBarTypeLeft左
         loadingBar->setDirection(LoadingBarTypeLeft);
        loadingBar->setPosition(Point(widgetSize.width / 2.0f,
                                      widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
        layout->addChild(loadingBar);
        
        
        
        _count = 0;
        
        scheduleUpdate();


void LayoutTest::update(float delta)
{
    _count++;
    
    if (_count  > 100) {
        _count = 0;
    }
    LoadingBar* loadingBar = static_cast<LoadingBar*>(layout->getChildByTag(0));
    loadingBar->setPercent(_count);
}

mamicode.com,码迷

Cocos2d-x3.0 LoadingBar

标签:cocos2d-x   extension   loadingbar   

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

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