Today the weather is very cloudy, it is going to rain soon, Chen eat early kung fu write something,
A cold autumn rain, 10 of the rain to wear cotton, you will henceforth wear a bit more
int Application:: Run ()
{
if(! Applicationdidfinishlaunching())
{
return 1;
}
long lasttime = 0L;
long curtime = 0L;
Auto director = Director::getinstance();
Auto glview = director->getopenglview();
//Retain Glview to avoid Glview being released in the while loop
Glview->retain();
//See, in fact all the games are in this loop
while (!glview->windowshouldclose())//If you do not exit, for example, the user presses home and exits.
{
Lasttime = Getcurrentmillsecond(); Get current system time
Director->mainloop(); 1. Working with game graphics and game logic
Glview->pollevents(); 2. Dealing with Game interactions
Curtime = Getcurrentmillsecond(); 3. the above 1.2 must consume a certain amount of time and the more animations and monsters may take a lot of time, so curtime-lasttime is how long this calculation consumes.
if (Curtime-lasttime < _animationinterval) //If Curtime-lasttime < _animationinterval
Description in 60/1 seconds to complete the calculation of this frame and then let the cup sleep fps remaining time to ensure the stability of the frame rate
{
Usleep (static_cast<useconds_t> ((_animationinterval -curtime + lasttime) *1000 ));
}
What if you want to know if there is any instability in the game? Add the following code
Else
{
//........
}
}
Do you understand, dear?
/* Only work on Desktop
* Director::mainloop is really one frame logic
* When we want to close the window, we should call Director::end ();
* Then call Director::mainloop to do release of internal resources
*/
if (glview->Isopenglready())
{
Director->end();
Director->mainloop();
}
glview->release();
return 0;
}
void application:: Setanimationinterval (double interval)
{
_animationinterval = interval*1000.0f;
}