File: js/modules/fps.js

Recommend this page to a friend!
  Classes of Pere Monfort   lightCyan   js/modules/fps.js   Download  
File: js/modules/fps.js
Role: Example script
Content type: text/plain
Description: fps module
Class: lightCyan
Render and update game objects in a canvas element
Author: By
Last change: Update of js/modules/fps.js
Date: 2 years ago
Size: 732 bytes
 

Contents

Class file image Download
lightCyan.addModule("fps", function (sandbox) { var currentFps = 0, frameCount = 0, lastFps = new Date().getTime(), oBuffer = sandbox.canvas.bufferContext; return { init : function () { sandbox.meeting.listen(["#draw#"], this.drawFps, this); }, drawFps : function(oNotification) { var thisFrame = new Date().getTime(); var diffTime = Math.ceil((thisFrame - lastFps)); if (diffTime >= 1000) { currentFps = frameCount; frameCount = 0.0; lastFps = thisFrame; } oBuffer.save(); oBuffer.fillStyle = '#000'; oBuffer.font = 'bold 12px sans-serif'; oBuffer.fillText('FPS: ' + currentFps + '/' + sandbox.settings.fps, 10, 15); oBuffer.restore(); frameCount += 1; } }; });