Login   Register  
Icontem

File: js/modules/fps.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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:
Date: 2012-02-10 00:09
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;

		}
	};

});