1:.h文件中设置计时器回调函数
void nextTime(float dt);
2:.cpp文件中添加计时器
//设置计时器
schedule(schedule_selector(GameScene0::nextTime),1.f,CC_REPEAT_FOREVER,1.f);
3:计时器回调函数
void GameScene0::nextTime(float dt)
{
if(countDown_time==0) //倒计时结束,停止计时器,进入下一局
{
unschedule(schedule_selector(GameScene0::nextTime));
countDown_text->setVisible(false);
countDown_time=3;
Round_Over();
}
else //倒计时下一秒
{
countDown_time--;
countDown_text->setString(String::createWithFormat("%d",countDown_time)->getCString());
}
}