I am trying to implement a radially disappearing clock image as a countdown. My sprite appears and is removed correctly, but no animation occurs, what should I do? Thank you!
I had just typed it directly into the forum. I noticed I forgot two semicolons. I put those back in. I just tried this code and it works. One thing to note, is that it was based on your original code. This puts the countdown timer in the bottom left hand corner.
If you’re going to be reusing the countdown timer often, this code is inefficient, as it always creates a new one instead of reusing one. If you want to reuse the countdown timer, you could do something like this:
void MainScene::init()
{
...
Size visibleSize = Director::getInstance()->getVisibleSize();
auto clock = Sprite::create("clock.png");
countdownTimer_ = ProgressTimer::create(clock);
countdownTimer_->setType(ProgressTimer::Type::RADIAL);
countdownTimer_->setPosition(visibleSize / 2); // this will put it at the center of the screen
this->addChild(countdownTimer_, kZOrderClock);
...
}
void MainScene::setupCountdown()
{
countdownTimer_->stopActionByTag(kCountdownActionTag); // kCountdownActionTag would need to be defined
auto reset = ProgressTo::create(0, 0);
auto progress = ProgressTo::create(kInitialDuration, 100);
auto progSeq = Sequence::create(reset, progress, NULL);
progSeq->setTag(kCountdownActionTag);
countdownTimer_->runAction(progSeq);
}
Never use a scheduler for a progress timer, as it’s timed/progressed on it’s own through an action. As @toojuice pointed out, it will contradict it’s purpose.
The animation does not show, cause you set one of the midpoint coordinates to zero. The radial progress timer needs space to wrap around. A value of 0 means, that it already reached that endpoint.
Also it changes it’s center point and for that reason it needs each bar change rate greater than zero.
The difference between your code and the one of @toojuice is, that it rotates counter clockwise instead of clockwise.
Do you want a centered radial progress timer? Than just apply these changes:
It’s also better to use floats for readability and getting rid of implicit casting, if the function takes floats. So maybe you want to use 1.0f instead of 1.