Hi, I am pretty new to Javascript and would like to play with the Canvas and I have a couple questions.
First off, how do I record frame rate or operations per second properly? In my current code I only get around 170 FPS with nothing on the canvas and the canvas being default size:
// GetElapsedMilliseconds = Function() { var time = new Date(); return time.getMilliseconds(); }
if (GetElapsedMilliseconds() - oldTime >=1000) {
OPS = count;
count = 0;
oldTime = GetElapsedMilliseconds();
}
++count;
loop = setTimeout('Main()', 1);
Another thing, am I doing Javascript's OOP implementation correctly?
myscene = new _Context("thecanvas");
function _Context(id) {
/*
description: Retrieve the canvas context by id, if it can't throw
an error and reason.
*/
if (document.getElementById(id)) {
this.canvas = document.getElementById(id).getContext("2d");
} else {
alert("Error\nUnable to find element ID: " + id);
return null;
}
this.DrawText = function(x, y, string, size, font, color) { // draw some text inside of the canvas
/*
description: Draw text to the canvas.
*/
this.canvas.font = size + "px " + font;
this.canvas.fillStyle = color;
this.canvas.fillText(string, x, y);
}
}