Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using requestAnimationFrame for logic updates? #19

Open
jeremyawon opened this issue Jul 19, 2013 · 1 comment
Open

using requestAnimationFrame for logic updates? #19

jeremyawon opened this issue Jul 19, 2013 · 1 comment

Comments

@jeremyawon
Copy link

I was looking over the implementation of setInterval in turbulenzengine.ts.

Using requestAnimationFrame surprises me since I thought only rendering would be done in an animationFrame callback, with game state updates happening through an independent loop.

Am I even right in thinking that, e.g., physics engine updates happen through WebGLTurbulenzEngine.setInterval and therefore in a requestAnimationFrame? Is there another interval system I'm overlooking?

In any case, this system clearly works well in turbulenz. Did the team try different architectures?

@ianballantyne
Copy link

Yes, updates and rendering are done in that way if you are looking to update at 60fps. We use request animation frame because its more reliable callback than window.setInterval for millisecond accurate callbacks on some browsers. You can of course use window.setInterval and window.setTimeout if you wish, but if precise timing is important to you then you should probably stick with TurbulenzEngine.setInterval.

One side note. On some browsers requestAnimationFrame won't be called if the tab being displayed is hidden. In Turbulenz we use this to make sure games are not updating when they are not visible. If you need to process i.e. doing networking processing etc, then you might want to use timeouts and/or intervals for keep alives and TurbulenzEngine.setInterval for rendering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants