hit2501 Posted December 4, 2017 Share Posted December 4, 2017 Hi everyone, I'm working on a web app that must change position of a mesh on (almost) every frame in time like a video. I know I can manage coordinates for this but I dont know how to set the fps to 30 and how to apply the new coordinates according to each frame. Can anybody show me a basic example to achieve this? Thank you all. Quote Link to comment Share on other sites More sharing options...
JohnK Posted December 4, 2017 Share Posted December 4, 2017 The fps can vary depending on the number of meshes and other conditions. If you want your mesh to move at a predetermined speed say V units per sec then you need to know how far to move per frame. When the frame rate is F fps then the time taken T for a given frame at that time is 1/F so the distance moved by the mesh is VT = V/F. scene.registerBeforeRender or scene.registerAfterRender can be used to make changes for one frame. So for a mesh with speed V in the direction of the X axis scene.registerBeforeRender (function (){ var F = engine.getFps (); mesh.position.x += V/F; }) hit2501 1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted December 4, 2017 Share Posted December 4, 2017 If you look at examples on the internet that build game loops using requestAnimationFrame() then you would likely want to use engine.getDeltaTime(). The amount of time passed can make a smoother animation than average frames / second. Depends on your needs there. The formula is easy though, if you want to move 5x / second and 10ms have passed then it's mesh.position += 5 * 0.01; To answer your question, I am not aware of a way to request 30 FPS on the engine, only on animations themselves. hit2501 1 Quote Link to comment Share on other sites More sharing options...
hit2501 Posted February 14, 2018 Author Share Posted February 14, 2018 Thank you both, I'll test it. 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.