June 9, 2011

I have been slacking on my blogging. At the beginning of May, I had several articles planned in which I would catalogue and immortalize all the great times I’d had and people I’d met during my four years at high school. But I had a project I wanted to complete (Infinite Mario in HTML5) and I was still in school and working part time at MetaGeek. Time was short, and after I got out of school it only got worse as I devoted all of my spare time to finishing Infinite Mario, with utter disregard for the rest of my obligations. Anyway, Mario is pretty much done now and the “sprint of epicness” is finally wrapping up at MetaGeek, so I can get back to writing some.

However, before I wax reminiscent I’d like to get a few opinions out there that developed as a result of my experience working on Infinite Mario. First, HTML5 is awesome and I definitely think it is the future. Porting Notch’s code from a Java Applet to a JavaScript canvas game was, for the most part, a breeze. I made a reusable game engine along the way, and I plan to make a few more small games to see what other functionality may be required in it. Overall, it was time consuming but simple enough.

But there were issues.

The State of HTML5 Audio

Currently, HTML5 Audio is disastrous. Hopefully this will soon change, but I must admit I was severely disappointed when I began to implement sound in the game. Perhaps the most irritating problem is the lack of universal support for even one file type. This means you have to include two different formats for each sound file you want to play. Eventually, I had to resort to using the embed element for music, and finally just had to remove the background music altogether due to incompatibility between different browsers and operating systems. I noticed that Firefox 4 generally had the best support for sound. Apparently both Chrome and Firefox have Audio Data APIs now, so there is a light at the end of the of this rather bumpy tunnel, but there’s still a long way to go before I’ll be satisfied with sound support in HTML5. Other issues I had to hack around include the lack of any easy looping method and the inability to have multiple instances of a sound playing simultaneously.

JavaScript Operator Overloading

I can see there being some problems with this one, due to the nature of JavaScript’s loosely typed syntax. However, I think it would be absolutely fantastic if JavaScript had operator overloading. In the development of a little structure to do vector math for me, I found I had to user methods where I’d normally use operator overloads in, say, C#. As a result, adding one 2D vector to another looks like:

vec1.add(vec2);

whereas, it could be something much easier to read (and thereby much more intuitive), like:

vec1 += vec2;

Of course, this is a bad example to explain my point. Here’s a better example using more complex operations.

v1.mul(v2).div(scalar).add(v3).sub(v4);
(v1 * v2 / scalar) + v3 - v4;

The second line, while still probably being a sign of too much complexity shoved into one place, is easier for me to read and understand than the line above it. Yet I am stuck lamenting the latter and pining for the former in my code. It is a menial issue, but nonetheless I would love to see some operator overloading in the next version of JavaScript.

That should just about sum it up, but I haven’t yet tried my hand at a browser-based multiplayer game, and that frontier will no doubt have its crevices of ugliness. But until then, I must admit being fairly satisfied with the state of 2D game development for HTML5. It works and works well... if you’re making a silent game.