Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:17:42+00:00 2026-06-15T17:17:42+00:00

I am making a game, and the requirement is to make it have at

  • 0

I am making a game, and the requirement is to make it have at least 30FPS and shouldn’t drop below. Would what I have below achieve this? Or am I off somewhere? Much help would be appreciated.

private long period = 6 * 1000000;
private static final int DELAYS_BEFORE_YIELD = 5;
long before, after, difference, sleep, oversleep = 0;
int delays = 0;
while (running)
{
    before = System.nanoTime();
    after = System.nanoTime();
    difference = after - before;
        if (sleep < period && sleep > 0)
    {
    try
    {
        Thread.sleep(sleep / 35000L);
        oversleep = 0;
    }
    catch (InterruptedException e)
    {

    }
    }
    else if (difference > period)
    {
    oversleep = difference - period;
    }
    else if (++delays >= DELAYS_BEFORE_YIELD)
    {
    Thread.yield();
    oversleep = 0;
    delays = 0;
    }
    else
    {
    oversleep = 0;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:17:43+00:00Added an answer on June 15, 2026 at 5:17 pm

    You can set an upper bound to frame rate but not a lower bound that is guaranteed to be always followed.

    You can make a function be called no more than 30 times per second but you can’t be sure it will be called at least 30 times per second. At 30 fps you have 0.03s of time that will be distributed between your threads and usually the drawing one is the heaviest between them all (unless you have complex operations like AI or whatever but that should be solved by lowering their rate or precomputing what can be precomputed).

    If time of draw + time of logic > 0.03 then there is no way to make your game run at least at 30fps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a game and would like to have a background loop of game
I'm making a little java game in which I would have two threads (well
I built a slideshow/decision-making game in Flash but would like to try to redo
I'm making some game, and I have made it pretty much all, but not
I am making a game, and have a Game model and a User model.
I am making a game engine using HTML5 canvas, and I have decided to
i am making a game using andengine in android, in this game various sprites(eggs)
I am making card game in C# WPF. For now I have singleplayer mode,
I'm making a game and I have stored the map data in a 2-dimensional
I'm making a game where the game's size varies, so I want to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.