Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
When dealing with games, delta time is important as it make sure the speed is the same for different refresh rate. I wish Coppercube have a built in variable call: system.deltatime. ccbGetCopperCubeVariable("system.deltatime"); //This will be a read only function, CANNOT and SHOULD NOT be set. This is the code: 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; //Or you can access this variable anytime you like, don't have to be inside this function. console.log(Delta_Time); delta_time_enterframe_handle = requestAnimationFrame(delta_time_enterframe); //cancelAnimationFrame(delta_time_enterframe_handle); } |
|