Created
November 8, 2017 18:25
-
-
Save soggybag/4e62f203553066836b62ae4c29908d11 to your computer and use it in GitHub Desktop.
Delta time to keep more accurate time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save the current time in ms | |
let lastUpdateTime = Date.now() | |
setInterval(() => { | |
// get the current time in ms | |
const now = Date.now() | |
// calculate the delta time as difference between now and the last update | |
const deltaTime = now - lastUpdateTime | |
// Set the last update to now. | |
lastUpdateTime = now | |
console.log(deltaTime); | |
// | |
store.dispatch( incrementAllTimers(deltaTime) ) // Call an update on the dispatcher | |
}, 500) // Updated happen approximately every half second |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment