Skip to content

Instantly share code, notes, and snippets.

@sushat4692
Created April 1, 2014 14:16
Show Gist options
  • Save sushat4692/9915015 to your computer and use it in GitHub Desktop.
Save sushat4692/9915015 to your computer and use it in GitHub Desktop.
Use requestAnimationFrame 30FPS
// 基準実行時間
var basetime = Date.now();
// FPS
var fps = 1000/30;
// setTimeoutを利用した場合は最初から30FPSで実行される
function animate_handler() {
var now = Date.now();
var check = now - basetime;
if( check / fps >= 1 ) {
basetime = now;
draw();
}
requestAnimationFrame( animate_handler, fps );
}
function draw() {
// 再描画処理
}
animate_handler();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment