0
以下方法在用戶操作後調用。代碼的目的是在不改變剩餘時間的情況下更改進度計時器的精靈。我的代碼改變了精靈,但它也增加了定時器的剩餘時間。金額每次都有所不同,但總是增加。我究竟做錯了什麼?在cocos2d-x 3.0中,如何在保持百分比的同時更改進度計時器的精靈?
用戶操作之前:
後用戶操作:
void TouchScene::switchColors(CustomTimer* centerTimer)
{
float time = myTimer->getPercentage();
myTimer->runAction(RemoveSelf::create());
createCenterTimer(time);
}
void TouchScene::createCustomTimer(float percentage)
{
myTimer = CustomTimer::create();
int iRandomColor = getNextColor();
std::string colorName = getColorName(iRandomColor);
myTimer->setName(colorName);
myTimer->setAngle((float)M_PI * 2);
/*pass the current percentage to the new timer*/
myTimer->drawTimer(percentage);
addChild(myTimer, 0);
}
void CustomTimer::drawTimer(float time)
{
/*removed standard positioning code*/
/*get the name of the next sprite*/
std::string name = getName().c_str();
Sprite *timerSprite = Sprite::create(name + ".png");
timer = ProgressTimer::create(timerSprite);
timer->setType(ProgressTimer::Type::RADIAL);
timer->setReverseDirection(true);
/*set the timer to pick up where the previous one left off...*/
timer->setPercentage(time); //gives inconsistent results
addChild(timer);
}
您可以顯示CustomTimer的代碼嗎? – bunty