キャンバス ゲーム アプリケーションの FPS を計算するにはどうすればよいですか? いくつかの例を見てきましたが、それらのどれも requestAnimationFrame を使用しておらず、そこにソリューションを適用する方法がわかりません。これは私のコードです:
(function(window, document, undefined){
var canvas = document.getElementById("mycanvas"),
context = canvas.getContext("2d"),
width = canvas.width,
height = canvas.height,
fps = 0,
game_running = true,
show_fps = true;
function showFPS(){
context.fillStyle = "Black";
context.font = "normal 16pt Arial";
context.fillText(fps + " fps", 10, 26);
}
function gameLoop(){
//Clear screen
context.clearRect(0, 0, width, height);
if (show_fps) showFPS();
if (game_running) requestAnimationFrame(gameLoop);
}
gameLoop();
}(this, this.document))
canvas{
border: 3px solid #fd3300;
}
<canvas id="mycanvas" width="300" height="150"></canvas>
ところで、パフォーマンスを監視するために追加できるライブラリはありますか?