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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:02:47+00:00 2026-06-12T17:02:47+00:00

I grabbed this from the book I’m learning from. public void run() { //

  • 0

I grabbed this from the book I’m learning from.

public void run()
{
    // this is the method that gets called when the thread is started.

    // first we get the current time before the loop starts
    long startTime = System.currentTimeMillis();

    // start the animation loop
    while (running)
    {
        // we have to make sure that the surface has been created
        // if not we wait until it gets created
        if (!holder.getSurface ().isValid())
            continue;

        // get the time elapsed since the loop was started
        // this is important to achieve frame rate-independent movement,
        // otherwise on faster processors the animation will go too fast
        float timeElapsed = (System.currentTimeMillis () - startTime);

        // is it time to display the next frame?
        if (timeElapsed > FRAME_RATE)
        {
            // compute the next step in the animation
            update();

            // display the new frame
            display();

            // reset the start time
            startTime = System.currentTimeMillis();
        }
    }

    // run is over: thread dies
}

Does it account for lag correctly and is it optimal?

What I mean is, if the video cannot update 60 times per second will the update() be called 60x per second?

Thanks

  • 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-12T17:02:48+00:00Added an answer on June 12, 2026 at 5:02 pm

    if the video cannot update 60 times per second will the update() be called 60x per second?

    The answer to this is no. At the beginning of every game loop, you calculate how long its been since your last game loop. You store this in “timeElapsed”.

    From here, you compare this to “FRAME_RATE”. “FRAME_RATE” is a misleading name, because in your case, it’s not your frame rate. You want a frame rate of 60. In order to wait for the appropriate amount of time, FRAME_RATE should be 1000(milliseconds)/60(frames per second).

    Now, at the beginning of every iteration, you take the elapsed time and test to see if it is time for the next frame. If it isn’t, you skip doing any actual processing or rendering, and you run the loop again.

    When the elapsed time finally surpasses the FRAME_RATE (which is really the frame delay), you perform your processing and you render the frame. Ideally, the amount of time it takes to do this will be less than your frame delay, allowing your next iteration to start on schedule. As long as this is the case, update() and display() will be called about 60 times per second.

    However, if the time it takes to render and process the frame is longer than your frame delay, then the next frame will be processed on the very next iteration, and it will be late. In this case, update() and display() will be called less than 60 times per second.

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

Sidebar

Related Questions

I grabbed this example from apples website This example seems to not run at
I'm working on a long string grabbed from a Session that uses § (Section
Grabbed this from a sample: protected override ObjectContext CreateDataSource() { NorthwindContext nw = new
I have this method on rails so that I have an image calling a
I grabbed this compact news reader from here Below is the code for animating
So I have this ruby code I grabbed from wikipedia and I modified a
I grabbed this snippet from another question: <script type='text/javascript' > $(document).ready(function () { $(div.content
Right now I successfully grabbed the full element from an HTML page with this:
I have some code that will be accessed from two threads: class Timer{ public:
I have a delimiter string like this: 2,3 which is grabbed from a listbox

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.