dav74 Posted November 4, 2013 Share Posted November 4, 2013 Hi,What is the best method for the use of the "time variable" in the game loop ?Thank you Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 4, 2013 Share Posted November 4, 2013 Hi Dav, Sorry, but I don't understand your question... You mean to keep an unchanged number of FPS ? Quote Link to comment Share on other sites More sharing options...
dav74 Posted November 4, 2013 Author Share Posted November 4, 2013 Hi Temechon thank you for your help (again ;-))for example in threeJS we have : var chrono=new THREE.Clock();//init world...............chrono.start(); function animation(){ t=chrono.getElapsedTime() sph2.position.x=80*Math.sin(t*0.7); sph2.position.z=80*Math.cos(t*0.7); } function play(){ requestAnimationFrame(play); animation(); renderer.render(scene, camera);}Does the "BABYLON.Clock()" constructor exist ?else how to do the same thing (to separate "time variable" and FPS) ? With 2 "GetCurentTime" at the beginning and at the end of the game loop ? Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 4, 2013 Share Posted November 4, 2013 I don't think the constructor BABYLON.Clock() exists today (but maybe Deltakosh will contradict me), but you can create it yourself (it may be a good exercise for your students ).I would create a new function using (new Date).getTime() to have the current time. Then, this method could be used at the beginning and at the end of your process. I think it's the easiest way to do it. Quote Link to comment Share on other sites More sharing options...
dav74 Posted November 4, 2013 Author Share Posted November 4, 2013 how reach the beginning and the end of the process ? In the "RenderLoop" function ?// Render loopvar renderLoop = function () { // Start new frame engine.beginFrame(); scene.render(); // Present engine.endFrame(); // Register new frame BABYLON.Tools.QueueNewFrame(renderLoop);};BABYLON.Tools.QueueNewFrame(renderLoop); Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 4, 2013 Share Posted November 4, 2013 If you want to know the time consumed to render your scene, you have access to this function : myScene.getRenderDuration();This function returns the time used to render the current scene (without any postprocess and without any actions registered with registerBeforeRender and registerAfterRender). If you want to know the time used by the whole render process (with postprocessing, AND actions registered with registerBeforeRender and registerAfterRender), then you can use the method myScene.getLastFrameDuration();If I still don't understand your question (shame on me ), you can send me an MP (in english or french) and I will try to help you the best I can. Cheers , Quote Link to comment Share on other sites More sharing options...
dav74 Posted November 4, 2013 Author Share Posted November 4, 2013 All is ok, i understood, thank you very much for your helpCheers, Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 4, 2013 Share Posted November 4, 2013 My pleasure GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Butterwell Posted November 30, 2015 Share Posted November 30, 2015 I found that using scene.getLastFrameDuration(); caused movement slowdowns (when multiplying rotation and translations by it) near large objects. I use this instead and everything is smooth:// Put this at the end of all the JavaScript, since it starts immediately.var clock = { before: performance.now(), getDelta: function () { var now = performance.now() var delta = now - this.before this.before = now return delta }} WolfKodi 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.