Skip to content

Instantly share code, notes, and snippets.

@soggybag
Created November 8, 2017 18:25
Show Gist options
  • Save soggybag/4e62f203553066836b62ae4c29908d11 to your computer and use it in GitHub Desktop.
Save soggybag/4e62f203553066836b62ae4c29908d11 to your computer and use it in GitHub Desktop.
Delta time to keep more accurate time.
// 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