kuuuurija Posted February 16, 2014 Share Posted February 16, 2014 Ya I know, more the FPS is better. I am getting FPS 58-60 across Chrome, Firefox in Android but for Opera FPS jumps to 100-120. Why is that? It makes all the animations too fast.Solution was to add setTimeout in update loop but that makes firefox slow (fps 30)? Have you guys faced this problem? any solutions? Quote Link to comment Share on other sites More sharing options...
iprasila Posted February 18, 2014 Share Posted February 18, 2014 You could simply calculate the fps and update your game at a fix rate. Are you using requestAnimationFrame in Chrome, Opera and Firefox ? What is your Android version ? Quote Link to comment Share on other sites More sharing options...
kuuuurija Posted February 18, 2014 Author Share Posted February 18, 2014 You could simply calculate the fps and update your game at a fix rate. Are you using requestAnimationFrame in Chrome, Opera and Firefox ? What is your Android version ? solved.ya, I am using requestAnimationFrame. (Android 4.1.x) I fixed it by adding requestAnimationFrame to setTimeout.var fps = 60;function draw() { setTimeout(function() { requestAnimationFrame(draw); // redraw code }, 1000 / fps);} Quote Link to comment Share on other sites More sharing options...
iprasila Posted February 18, 2014 Share Posted February 18, 2014 I think you are doing a mistake if you mix setTimeout with requestAnimationFrame, what I suggested was to effectively calculate the fps and do the game logic update at a fixed fps. setTimeout and setInterval are not meant to be used for a draw cycle. Anyway if you are satisfied with how it works now ... Quote Link to comment Share on other sites More sharing options...
kuuuurija Posted February 19, 2014 Author Share Posted February 19, 2014 it is going to be tricky to manage my own FPS system.marked it unresolved for now. Quote Link to comment Share on other sites More sharing options...
moe091 Posted February 25, 2014 Share Posted February 25, 2014 I'm new to html5, but usually all realtime games should have what's called a fixed timestep. Which is basically what iprasila was talking about. All you need to do for a simple implementation is change all your fps based values to time based values(e.g instead of setting velocity to 2 pixels per frame, set it to 2 pixels per 50ms). Then in all your update code find the amount of time that elapsed since the last frame and when you update your objects use the elapsed time as a multiplier for your values(using the velocity example: position.x = position.x + velocityPer50ms.x * (timeElapsedInMs / 50)) drhayes 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.