Firstly my apologies for the random theme change. I’m forever trying to find the perfect theme for this blog. FWIW I rather like this one so will stick with it for about a week or so :-)
I added a feature whereby I could write numbers to screen based on my own character set.
The character set is actually little more than an image with characters positioned at equal space throughout and then called up using the drawImage() method.
The above is 240×48 pixels in dimension. Each number is sat within a 24 x 48 grid. My x offset is therefore set to 24 pixels.
So in the case of “00001950” the first four numbers use the calculation 0 x 24 to locate the left hand side of the desired character. The y offset is constantly 0 (zero).
Using drawImage(image, xoffset, yoffset, width, height, canvasx, canvasy, width, height) I can then print a string of numbers from my numbers.png file.
e.g. for the 6th character in the string I would be using
drawImage(numbers, (9 * 24) ,0 ,canvasx ,canvasy ,24 ,48);
where canvasx is bumped by the x offset each time.
Once I had this figured as a function I knew that I could pass a string and a starting x, y to it. So I implemented a frame rate counter and dumped it bottom right on the screen.
Interestingly I got best results from Internet Explorer 9 P6. Chrome was a very close second with Opera, Safari and (a surprisingly poor) Firefox 3.6 in last place. At best I was getting around 22 FPS which when the loop is throttled at around that in the code is no surprise. Despite this Firefox couldn’t get close pulling in around 16 to 18 instead.
When the code is run flat out (i.e. setTimeout() set to zero) Chrome can get over a hundred. IE close behind.
To see such fabulous performance across all popular browsers is thrilling to say the least.
IE finally playing the game just does it for me. It means that games using this technology can be played by everybody someday.
Note: I also tested using the iPad and got around 7FPS. Room for improvement in the way that I throttle the loop perhaps.
Play the latest version here: www.wilfscorner.co.uk/sandpit/1/castle.php