ardeay
February 12, 2014, 5:22pm
#1
I’m looking to create the effect of adding points (1 by 1) this is what I have
// start is our current amount, amount is the amount to change
void HudLayer::removePoints(LabelTTF* label,int start,int amount)
{
for(int i = amount; i >= 0; i--){
// ideally a wait call would happen here
label->setString(std::to_string(start - i));
}
}
I looked for a sleep or wait call in c++ but found you need additional classes, is there anything in Cocos2dx to accomplish this?
c++, linux, sleep
Jgod
February 12, 2014, 5:48pm
#2
Yes, there are at least two ways to do this off the top of my head.
You can use CCSequence and run an action with a delay:
CCFiniteTimeAction* const CALLBACK = CCCallFunc::create(this, callfunc_selector(MyScene::callback));
// Wait one second before triggering callback
this->runAction(CCSequence::create(CCDelayTime::create(1.0f), CALLBACK, NULL));
You can schedule a function to run based on an interval:
// Interval of one second
this->schedule(schedule_selector(MyScene::callback), 1.0f);
Randy, why not use std::chrono::sleep?
ardeay
February 12, 2014, 8:43pm
#4
slackmoehrle wrote:
Randy, why not use std::chrono::sleep?
I just did, it ended up freezing the screen that time then picking back up and the numbers were changed. It must be stopping cocos operations as well.
Reference for stopping time outside of cocos2d: http://stackoverflow.com/questions/4184468/sleep-for-milliseconds
ardeay
February 12, 2014, 8:47pm
#5
Thanks J I’ll try these out tonight!
Jgod wrote:
Yes, there are at least two ways to do this off the top of my head.
You can use CCSequence and run an action with a delay:
CCFiniteTimeAction* const CALLBACK = CCCallFunc::create(this, callfunc_selector(MyScene::callback));
// Wait one second before triggering callback
this->runAction(CCSequence::create(CCDelayTime::create(1.0f), CALLBACK, NULL));
You can schedule a function to run based on an interval:
// Interval of one second
this->schedule(schedule_selector(MyScene::callback), 1.0f);