8_ Game Loop

Source: Internet
Author: User

``` while(true) {Event*Event=waitforevent (); Dispatchevent (Event);} while(true) {processinput ();  Update (); Render ();} The game loop is executed during the game run, each cycle will process user input, update the game state, render the scene, etc. Record the cycle time to control the rhythm (rate) of the game. "\ \ Lock Frame rates while(true){  DoubleStart =GetCurrentTime ();  ProcessInput ();  Update ();  Render (); Sleep (Start+ Ms_per_frame-getcurrenttime ());} \ elapsed, the frame rate is not fixed, but the game uses the time difference to update \ \ Different frame rate, the physical motion results are the sameDoubleLasttime =getcurrenttime (); while(true){  DoubleCurrent =GetCurrentTime (); DoubleElapsed = current-Lasttime;  ProcessInput ();  Update (elapsed);  Render (); Lasttime=Current ;} "' \ \ \ \ \ \ \ \ \ \ \" \ \ \ \ ""DoublePrevious =getcurrenttime ();Doublelag =0.0; while(true){  DoubleCurrent =GetCurrentTime (); DoubleElapsed = current-previous; Previous=Current ; Lag+=elapsed;  ProcessInput ();  while(Lag >=ms_per_update)    {update (); Lag-=ms_per_update;  } render (); //prevent the object from beatingRender (lag/ms_per_update);} "' # # Power consumption1the frame rate is as high as possible. will bring a better experience, will also be with electricity, heat more2Limit the frame rate. Bring a good enough experience and reduce power consumption

8_ Game Loops

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.