Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Position_X += 1 * dt for example to make sure it moves 1 pixel exactly every one second. Delta means a change in a quantity, so delta-time means the change in time. It is the time, in seconds, since the last tick. For example, at 100 fps dt will be 0.01 (one hundredth of a second), and at 10 fps dt will be 0.1 (one tenth of a second). In practice, dt varies tick-by-tick, so it is unlikely to be exactly the same value for long periods of time. Every tick (once per frame), the object moves one pixel to the right. Notice that at 30 FPS this means 30 pixels per second, and at 60 FPS this means 60 pixels per second. Those are different speeds, depending on the framerate. But if you do + 1 pixel * deltaTime then it will always be the same ! So is there a deltaTime in CopperCube ? Since we cannot just assume that the refresh rate will always be the same, it would be very foolish to assume so. |
||||
|
Try to use parseInt(new Date().getTime()/1000); |
||||
|
Hello chenhongye, new Date() doesn't work in Windows.exe only work in WebGL. print (new Date() ); //Run it as *.exe in coppercube and see what got print out. It is CRAZY ! console.log (new Date() ); //Run it exported to WebGL and it works PERFECTLY in browser. This is the bug thread and screenshot: https://www.ambiera.com/forum.php?t=7330 |
||||
|
You need to write it completely. print(new Date().getTime()); |
||||
|
I am trying to create a delta time in JS first before I change it into Coppercube's ccbRegisterOnFrameEvent, I couldn't get the ball to move left to right smoothly. <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Delta Time</title> <style type="text/css"> body,td,th { font-family: consolas; font-weight:bold; font-size: 50px; color: F90; } body { border:0; margin:0; padding:0; background-color: 000; overflow:hidden; } container { width:100vw; height:100vh; display:grid; place-items:center; } delta_Time { color:7f84ff; } </style> <script src="jquery-1.11.1.min.js"></script> <script> var Delta_Time_Last_Update = Date.now(); var Delta_Time_Now = 0; var Delta_Time = 0; var delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe); function delta_time_enterframe(event) { Delta_Time_Now = Date.now(); Delta_Time = (Delta_Time_Now - Delta_Time_Last_Update) / (1000/60); Delta_Time_Last_Update = Delta_Time_Now; $("delta_Time").html(Delta_Time); $("ball").css("left",(parseFloat($("ball").css("left").replace(/[^-\d\.]/g, ''))+0.2)*parseFloat(Delta_Time)+"px"); console.log($("ball").css("left").replace(/[^-\d\.]/g, '')); delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe); //cancelAnimationFrame(delta_time_enterframe_handle); } </script> </head> <body> <div id="container"> <table width="800px" border="1"> <tr> <td align="right" style="color:cc99cc;" width="330px">Delta Time:</td> <td> <div id="delta_Time" style="margin-left:7px;"> 0000 </div> </td> </tr> </table> </div> <div id="ball" style="position:absolute; left:10px; top:10px; background-color:0F0; width:100px; height:100px; border-radius:100px;"></div> </body> </html> What's wrong with my delta time ? |
||||
|
It's ok, I have fixed it ! Sorry, Looks like my delta time retrieval function works !!! <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Delta Time</title> <style type="text/css"> body,td,th { font-family: consolas; font-weight:bold; font-size: 50px; color: F90; } body { border:0; margin:0; padding:0; background-color: 000; overflow:hidden; } container { width:100vw; height:100vh; display:grid; place-items:center; } delta_Time { color:7f84ff; } </style> <script src="jquery-1.11.1.min.js"></script> <script> var Delta_Time_Last_Update = Date.now(); var Delta_Time_Now = 0; var Delta_Time = 0; var delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe); function delta_time_enterframe(event) { Delta_Time_Now = Date.now(); Delta_Time = (Delta_Time_Now - Delta_Time_Last_Update) / (1000/60); Delta_Time_Last_Update = Delta_Time_Now; $("delta_Time").html(Delta_Time); $("ball").css("left",(parseFloat($("ball").css("left").replace(/[^-\d\.]/g, ''))+(0.2 * Delta_Time))+"px"); console.log($("ball").css("left").replace(/[^-\d\.]/g, '')); delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe); //cancelAnimationFrame(delta_time_enterframe_handle); } </script> </head> <body> <div id="container"> <table width="800px" border="1"> <tr> <td align="right" style="color:cc99cc;" width="330px">Delta Time:</td> <td> <div id="delta_Time" style="margin-left:7px;"> 0000 </div> </td> </tr> </table> </div> <div id="ball" style="position:absolute; left:10px; top:10px; background-color:0F0; width:100px; height:100px; border-radius:100px;"></div> </body> </html> |
|