Created
April 1, 2014 14:16
-
-
Save sushat4692/9915015 to your computer and use it in GitHub Desktop.
Use requestAnimationFrame 30FPS
This file contains 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
// 基準実行時間 | |
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