FalseProphet Posted April 16, 2012 Share Posted April 16, 2012 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); } } Quote Link to comment https://forums.phpfreaks.com/topic/261056-html5javascript-couple-questions-particularly-dealing-with-canvas/ Share on other sites More sharing options...
Alex Posted April 24, 2012 Share Posted April 24, 2012 170FPS is probably right. Browsers throttle timers to a minimum limit, so your setTimeout('Main()', 1) isn't being called every millisecond. Each browser is different, I think for chrome the minimum is 3ms and for FF it's 5ms or something like that, but don't quote me on it. Quote Link to comment https://forums.phpfreaks.com/topic/261056-html5javascript-couple-questions-particularly-dealing-with-canvas/#findComment-1340231 Share on other sites More sharing options...
haku Posted April 25, 2012 Share Posted April 25, 2012 170fps may be overboard. I believe TV runs around 24 frames per second, and according to wikipedia, video games are thought to be acceptable at 30-60fps, though some go over 100. Quote Link to comment https://forums.phpfreaks.com/topic/261056-html5javascript-couple-questions-particularly-dealing-with-canvas/#findComment-1340316 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.