Game frame speed processing

Source: Internet
Author: User

Game frame speed processing

It is important to maintain the smoothness of the game on different performance mobile phone platforms. Therefore, we need to set appropriate frame speeds for hardware that cannot be connected. Generally

If the frame speed of a mobile phone user is 40/s, the related parameters and Code are as follows:

// ================================================ ====================
// Adjust the frame speed of the game
// ================================================ ====================
Private long framerate = 1000/40; // sets the frame speed to 40 frames per second (25 MS/frame)
Private long framestart; // The time when the frame starts. The frame begin
Private long framecount = 0; // Number of frames in this second
Private long elapsedtime; // time consumed by one frame
Private long totalelapsedtime = 0; // time consumed by multiple frames
Private long reportedframerate; // The actually calculated frame rate.

Public void updateframe ()
{
Framestart = system. currenttimemillis ();
Repaint ();
Elapsedtime = system. currenttimemillis ()-framestart;

// Frame Rate Synchronization
Try {
If (elapsedtime <framerate ){
Thread. Sleep (framerate-elapsedtime );
} Else {
Thread. Sleep (5 );
}
} Catch (exception e ){
E. printstacktrace ();
}

// Update the actual Frame Rate
++ Framecount;
Totalelapsedtime + = (system. currenttimemillis ()-framestart );
If (totalelapsedtime & gt; 1000 ){
Reportedframerate = (long) (double) framecount/(double)

Totalelapsedtime * 1000.0 );
// The frame rate can be displayed on the screen during debugging.
// G. drawstring ("FPS:" + reportedframerate, X, Y, 0 );
Framecount = 0;
Totalelapsedtime = 0;
}
}

 

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.