How to schedule a function in pause game status()???

Hello,

Actually I want to resume a game after 5 sec of pause game status?? I did this, but it’s not working…

void HelloWorld::pauseGame()
{
CCLog(“Inside pauseGame”);
this~~>unscheduleAllSelectors;
CCDirector::sharedDirector~~>pause;
this~~>resumeGame; // This line working. It’s call resume function
this~~>schedule( schedule_selector(HelloWorld::resumeGame), 5.0f); //This line Not working. It’s not call resume function
}

void HelloWorld::resumeGame()
{
CCLog(“Inside resumeGame”);
CCDirector::sharedDirector()>resume;
this
>unscheduleAllSelectors();
}

How I resume a game after some moment of time?

Hi, John Smith

After you invoke “CCDirector::sharedDirector()>pause", all schedule will be paused, so this>schedule() will not take effect.
Look at here
<pre>
void CCDirector::drawScene(void)
{
// calculate”global" dt
calculateDeltaTime();

//tick before glClear: issue #533
if (! m_bPaused)
{
CCScheduler::sharedScheduler()->tick(m_fDeltaTime);
}

}

In my opinion, you should use system timer to compute time after invoking “CCDirector::sharedDirector()->pause()”. But don’t use this method in the other logic of your game.:slight_smile:
Does anybody have a better method?:slight_smile:

Ok… that’s fine scheduler not work on pause state, but Is there any other option to pause game or resume my game after 5 second OR after some time???

The main loop of engine is CCDisplayLinkDirector::mainLoop().
Different platforms invoke this method to draw frames.
May be you can stop invoke this method to achieve your requirement.

Sorry Minggo, I don’t understand what you want to say…Please explain something more or give some reference…

James Chen wrote:

Hi, John Smith
>
After you invoke “CCDirector::sharedDirector()>pause", all schedule will be paused, so this>schedule() will not take effect.
Look at here
[…]
how about provide a function pointer to CCDirector, which will be called in each frame even if the CCDirector been paused?
<pre>
void CCDirector::drawScene(void)
{
// calculate”global" dt
calculateDeltaTime();

// here
*(this->ticker)(fDeltaTime);

//tick before glClear: issue #533
if (! m_bPaused)
{
CCScheduler::sharedScheduler()->tick(m_fDeltaTime);
}

}

Timothy Zhang wrote:

how about provide a function pointer to CCDirector, which will be called in each frame even if the CCDirector been paused?
[…]

It’s a way to achieve that, but you should calculate the delta time to total time, because you can not use the schedule after game is paused.
Just have a try.:slight_smile:

James Chen wrote:

Timothy Zhang wrote:
> how about provide a function pointer to CCDirector, which will be called in each frame even if the CCDirector been paused?
> […]
>
It’s a way to achieve that, but you should calculate the delta time to total time, because you can not use the schedule after game is paused.
Just have a try.:slight_smile:

In fact we are just doing like that in our games. delta time is a bit meaningless here.

It would be very nice if it would be added to next release.