进度条的实现(ProgressTimer)

a).h文件定义一个变量ProgressTimer* loadProgress;

重写父类void update(float delta);

b).cpp文件

bool Loading::init()

{

...............

auto sp = Sprite::create("progress_up_bg.png");

loadProgress = ProgressTimer::create(sp);//创建进度条

loadProgress->setBarChangeRate(Vec2(1,0));//进度条变化的速率

loadProgress->setType(ProgressTimer::Type::BAR);

loadProgress->setMidpoint(Vec2(0,1));

loadProgress->setPosition(_screenWidth/2,_screenHeight/2 - 200);

loadProgress->setPercentage(0.0f);

this->addChild(loadProgress,2);

 

scheduleUpdate();

return true;

}

void Loading::update(float delta)

{

float a = loadProgress->getPercentage();

a+=1;

if (a <= 100)

{

loadProgress->setPercentage(a);

}else

{

auto scene = MainScene::createScene();

Director::getInstance()->replaceScene(scene);

}

}

你可能感兴趣的:(Cocos2d-x)