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 6025395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:17:42+00:00 2026-05-23T04:17:42+00:00

I have a C++ game running through JNI in Android. The frame rate varies

  • 0

I have a C++ game running through JNI in Android. The frame rate varies from about 20-45fps due to scene complexity. Anything above 30fps is silly for the game; it’s just burning battery. I’d like to limit the frame rate to 30 fps.

  • I could switch to RENDERMODE_WHEN_DIRTY, and use a Timer or ScheduledThreadPoolExecutor to requestRender(). But that adds a whole mess of extra moving parts that might or might not work consistently and correctly.
  • I tried injecting Thread.sleep() when things are running quickly, but this doesn’t seem to work at all for small time values. And it may just be backing events into the queue anyway, not actually pausing.

Is there a “capFramerate()” method hiding in the API? Any reliable way to do this?

  • 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-05-23T04:17:43+00:00Added an answer on May 23, 2026 at 4:17 am

    The solution from Mark is almost good, but not entirely correct. The problem is that the swap itself takes a considerable amount of time (especially if the video driver is caching instructions). Therefore you have to take that into account or you’ll end with a lower frame rate than desired.
    So the thing should be:

    somewhere at the start (like the constructor):

    startTime = System.currentTimeMillis();
    

    then in the render loop:

    public void onDrawFrame(GL10 gl)
    {    
        endTime = System.currentTimeMillis();
        dt = endTime - startTime;
        if (dt < 33)
            Thread.Sleep(33 - dt);
        startTime = System.currentTimeMillis();
    
        UpdateGame(dt);
        RenderGame(gl);
    }
    

    This way you will take into account the time it takes to swap the buffers and the time to draw the frame.

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

Sidebar

Related Questions

Ok, I have my android game running smooth but can't get it to advance
Hi i have a custom view running my game. Once the player loses it
I run a game and the running is done by hand, I have a
I am making a fighting game in Flash and while I have everything running,
I have a bit of an unusual question. I'm running an old DOS game
I have a game in which you can score from -40 to +40 on
There is an interesting problem at hand. I have a role-playing MMOG running through
I have been working on an Android game for the past 6 months or
I have a game which has surfaceview and running on a thread. if I
I have a game running on the iPad that I'm trying to get running

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.