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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:58:18+00:00 2026-06-04T20:58:18+00:00

If a game is running at 177FPS or 22FPS, how is the player movements

  • 0

If a game is running at 177FPS or 22FPS, how is the player movements calculated? I’m trying to do this in Javascript:

setInterval(update, 0);

function update() {
     player_x++;
}

preview of problem

Problem is if the player will be move faster/slower according to the frame rate. How would I solve 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-06-04T20:58:21+00:00Added an answer on June 4, 2026 at 8:58 pm

    I highly recommend using requestAnimationFrame when available (which will get you the best frame rate possible in modern browsers) and setTimeout when not. Then base your players position on the time since the animation started:

    // Anonymous function used to make variables declared inside it not global
    // This avoids conflicts in case variables with the same names are used
    // in other scripts
    (function(){
    
        // This checks for the requestAnimationFrame in each browser and store the first
        // it finds into requestAnimationFrame. If none are found it uses setTimeout
        // Attempting 60 frames per second.
        // It's taken from Paul Irish's blog: http://paulirish.com/2011/requestanimationframe-for-smart-animating/
        // and you can use it as is
        var requestAnimationFrame = (function(){
            return window.requestAnimationFrame    || 
                   window.webkitRequestAnimationFrame || 
                   window.mozRequestAnimationFrame    || 
                   window.oRequestAnimationFrame      || 
                   window.msRequestAnimationFrame     || 
                   function(callback){
                       setTimeout(function(){ callback((new Date).getTime()); }, 1000/60);
                   };
        })();
    
        var speed = 60; // pixels per second
    
        // This is used so that we only divide by 1000 once instead of every frame
        var calc = speed/1000;
    
        // Store the current time in start_time
        var start_time = (new Date).getTime();
    
        // This function is self invoking. It is wrapped in parenthesis and called immediately
        // time is passed in by requestAnimationFrame
        (function draw(time){
            // Calculate the new x position based on the current time
            var pos = (time - start_time)*calc;
    
            // Update the player's position
            // In my JSFiddle I update the style.left of a div
            player_x = pos;
    
            // Now that this frame is done request another frame.
            // draw will be called again before that frame is rendered
            requestAnimationFrame(draw);
        })();
    
    })();
    

    JSFiddle

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

Sidebar

Related Questions

Hi i have a custom view running my game. Once the player loses it
I'm trying to automate some stuff on a flash game running in a webbrowser
Game.java calls a function getLabel() present in board.java. When I am running Game.java, I
I am trying to get my game running smoothly on android using PlayN, everything
I have a game running on the iPad that I'm trying to get running
I'm trying to develop a game and running into a small issue with NSTimer,
I am trying to get my game to scroll as a player along the
Ok, I have my android game running smooth but can't get it to advance
As the title says, I'm running multiple game servers, and every of them has
I am making a fighting game in Flash and while I have everything 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.