#ifndef __T05ProgressTimer_H__
#define __T05ProgressTimer_H__
#include "cocos2d.h"
USING_NS_CC;
static const char *files[]
{
"arrows.png ",
"arrowsBar.png ",
"assetMgrBackground2.png ",
"assetMgrBackground3.png ",
"atlastest.png ",
" b1.png ",
" b2.png ",
" background.png ",
" background1.png ",
" background2.png ",
"background3.png ",
" ui.png ",
"white - 512x512.png ",
" YellowSquare.png ",
" YellowTriangle.png ",
};
class ProgressTimer:public Layer
{
public:
T05ProgressTimer();
~T05ProgressTimer();
CREATE_FUNC(T05ProgressTimer);
bool init()
{
Layer::init();
/*条形进度条*/
/*背景*/
auto size = Director::getInstance()->getWinSize();
auto sp1 = Sprite::create("loadingbar.png");
/*背景上面的精灵图片*/
auto sp2 = Sprite::create("slidbar.png");
ProgressTimer *timer = ProgressTimer::create(sp2);
/*第一个参数是时间,第二个参数是显示的比例*/
ProgressTo *to = ProgressTo::create(10, 100);
_timer = timer;
/*父子关系*/
addChild(sp1);
sp1->addChild(timer);
/*位置关系*/
sp1->setPosition(size.width / 2, size.height / 2);
timer->setPosition(sp1->getAnchorPointInPoints());
/*设置进度条的类型*/
timer->setType(ProgressTimer::Type::BAR);
/*设置进度条的中心点*/
timer->setMidpoint(Vec2(0, 0));
/*设置方向是否显现*/
timer->setBarChangeRate(Vec2(1, 0));
/*设置显现比例*/
//timer->setPercentage(50);
timer->runAction(to);
/*弧形进度条*/
auto spH = Sprite::create("sliderThumb.png");
ProgressTimer *timerH = ProgressTimer::create(spH);
_timerH = timerH;
timerH->setPosition(200, 200);
addChild(timerH);
//timerH->setPercentage(0);
//sum = sizeof(files) / sizeof(*files);
//num = 0;
//schedule(schedule_selector(T05ProgressTimer::progress), 0.5f);
return true;
}
ProgressTimer *_timer;
ProgressTimer *_timerH;
int i = 0;
int sum;
int num;
void progress(float dt)
{
i++;
/*加载文件到缓存中*/
char buf[256];
sprintf(buf, "Images/%s", files[num++]);
Director::getInstance()->getTextureCache()->addImage(buf);
//_timer->setPercentage(num*100/sum);
_timerH->setPercentage(i*10);
/*if (i >= 10)
{
unschedule(schedule_selector(T05ProgressTimer::progress));
}*/
}
};