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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:15:31+00:00 2026-06-09T15:15:31+00:00

So, maybe total brainfart here. The syntax for setInterval() is pretty clear. Do something

  • 0

So, maybe total brainfart here. The syntax for setInterval() is pretty clear. Do something every x miliseconds. How is this best translated to using the requestAnimationFrame() ?

I have about 300 objects and each is supposed to perform an animation sequence at a certain interval (every 8, 6, 2, etc seconds)? How can I best accomplish this using requestAnimationFrame() which gets called ~60 times a second? There is probably an easy answer, I just, for the life of me, can’t figure it out.

  • 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-09T15:15:33+00:00Added an answer on June 9, 2026 at 3:15 pm

    requestAnimationFrame is pretty low level, it just does what you already said: roughly gets called at 60fps (assuming the browser can keep up with that pace). So typically you would need to build something on top of that, much like a game engine that has a game loop.

    In my game engine, I have this (paraphased/simplified here):

    window.requestAnimationFrame(this._doFrame);
    
    ...
    
    _doFrame: function(timestamp) {
         var delta = timestamp - (this._lastTimestamp || timestamp);
    
         for(var i = 0, len = this.elements.length; i < len; ++i) {
             this.elements[i].update(delta);
         }
    
         this._lastTimestamp = timestamp;
    
         // I used underscore.js's 'bindAll' to make _doFrame always
         // get called against my game engine object
         window.requestAnimationFrame(this._doFrame);
     }
    

    Then each element in my game engine knows how to update themselves. In your case each element that should update every 2, 6, 8 seconds needs to keep track of how much time has passed and update accordingly:

    update: function(delta) {
         this.elapsed += delta;
    
         // has 8 seconds passed?
         if(this.elapsed >= 8000) {
              this.elapsed -= 8000;  // reset the elapsed counter
              this.doMyUpdate(); // whatever it should be
         }
     }
    

    The Canvas API along with requestAnimationFrame are rather low level, they are the building blocks for things like animation and game engines. If possible I’d try to use an existing one like cocos2d-js or whatever else is out there these days.

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

Sidebar

Related Questions

Maybe my title is not the best but here is what I really want.I
Maybe it's because of the dark outside, but I can't get this Position geom_text
Maybe it's wrong but I always use this query for my app: cme_only =
Maybe this is a poor question, but, I can't find a tutorial or even
This is a question maybe already asked. My query is SELECT Year, Month, Line,
I'm a total database newbie and I'm probably using the wrong terminology to search
Is it possible to make a upload progress using javascript only? (maybe with some
I am currently using cast on a melted table to calculate the total of
What is the best MySQL command to count the total number of rows in
I've tried everything to figure this out but I can't get the correct total.

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.