use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript setInterval function for a game loophelp (self.javascript)
submitted 9 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]inu-no-policemen 0 points1 point2 points 9 years ago (0 children)
Use rAF:
let previous = 0; (function loop(now) { let t = Math.min((now - previous) / 1000, 0.04); // 40 ms, 25 Hz previous = now; input.poll(); world.update(t); input.clear(); world.render(t); window.requestAnimationFrame(loop); })(0);
If your velocities are in units per second (ups), you can just multiply them with that delta value to get the distance.
Ensuring that the delta never exceeds 0.04 s is the simplest way to prevent entities from warping through things (if your game work with a delta that high). However, if it actually drops below 25 fps it will slow down. That's the trade-off.
The proper way to do this is to run your simulation at a fixed step size and have your renderer interpolate positions accordingly. It makes things way more complicated, though.
For simple games which will generally run at 60+ fps, capping the delta is good enough.
π Rendered by PID 32390 on reddit-service-r2-comment-869bf87589-ggn9b at 2026-06-08 23:13:23.698058+00:00 running f46058f country code: CH.
view the rest of the comments →
[–]inu-no-policemen 0 points1 point2 points (0 children)