Friday, October 29, 2010

Jangaron 0.71: fix for IE9 beta

Another new browser version needs another patch.
This time, it's IE9 beta: alas, it became too standards-compliant! Thus, a typical crude workaround needed for IE6/7/8 did not work anymore. I fixed it, so you can now enjoy Jangaron in Internet Explorer 9 (beta)! It's fast and it's fun!

Evaluation
In IE < 9, you will run into problems when trying to dynamically create an input field by code like this:
  var input = document.createElement("input");
  input.setAttribute("type", "radio");
Old IEs refuse to interpret the type, also if you set it as a JavaScript attribute. Thus, you are forced to use a proprietary, IE-specific API extension that allows to hand in HTML fragments instead of the element name:
// only works in IE < 9:
  var input = document.createElement("<input type='radio'>");
Unfortunately, the usual way to do feature detection instead of browser detection does not apply here, since the function createElement() is defined in any browser, only old IEs provide additional semantics. So I did browser detection (shame on me), which of course failed when IE 9 (note: only in IE 9 mode, not in any backwards-compatibility mode!) became standards-compliant.
The only way out was to use the anti-pattern programming by exceptions and simply try the extended API and catch the error for standards-compliant browsers. To avoid recurring runtime penalty, I only do this once and store the result in a feature flag:
  var SUPPORTS_CREATE_ELEMENT_WITH_ATTRIBUTES = function() {
    try {
      window.document.createElement("<input type='text'>");
      return true;
    } catch (e) {
      return false;
    }
  }();
Instead of SUPPORTS_... I should maybe call that flag REQUIRES_..., since I do not use this feature because it is supported, but because the way the standard suggests does not work in old IEs.

Tuesday, September 21, 2010

The Story Continues: Jangaron 0.70

I just promoted version 0.60 to "stable" and uploaded a new "experimental" version 0.70. 0.43 is no longer linked (though still online) and 0.54 is now the "old" version.
Here are the highlights of the new experimental version 0.70:
  • Using soundManager2 for HTML5 sound that works in modern browsers without any plugin and even on iOS (iPhone, iPod touch, iPad)! Well, still quite experimental, but it's a proof of concept... As a fall-back, if available, Flash is still used. Moreover, I had to repair stuff to make it work on iOS again.
  • New controls  In single-player mode, you can now press Shift or Ctrl combined with the arrow keys. What happens is that when you hold down a modifier key, releasing the arrow key will turn your lightcycle again! Using Shift, you turn in the opposite direction, while using Ctrl, you turn in the same direction. Thus, you can do side-steps (Shift + arrow) and U-turns (Ctrl + arrow), and the time between pressing and releasing the arrow key determines the "width" of the move. Be warned that holding down the key for too long will trigger key repeat, and you will most likely crash! Maybe I can fix that...
  • Improved team lightcycle resurrection  When you play in a team with other programs and you crash, you are transferred into another lightcycle of your team. So far, this move was so confusing that usually, you immediately crashed again. Now, the view port changes to the other lightcycle, but it remains controlled by the program until you press the first controlling key. Thus, you can relax and wait for a not-so-close situation until taking over control, or just decide to watch the game continue. I plan to visualize the state in which the program has control over the viewport's lightcycle.
  • More technically, I used the latest Jangaroo compiler to recompile all libraries and the game itself. Should not really make any difference in game play, but leads to cleaner JavaScript code and a better build process. I hope to be able to put all Jangaron source code on github soon.
Please tell me what you think about the new features and whether they work for you!

P.S.: For those of you who are bored with the splash screen and voice, there is a secret switch: Just add ?nosplash to the URL, and you'll be directed to the settings dialog immediately, like this: http://www.jangaron.net/jangaron0.7/jangaron.html?nosplash

Tuesday, September 14, 2010

Eventually: Jangaron + Sound in Firefox 3.6

Greetings, programs, it's been quite a while.
Jangaron looks a bit abandoned, doesn't it? Well, you may be right. I've been working hard on the "parent" project Jangaroo and its Flash compatibility: see this new Flash-ported-to-Jangaroo Demo!
But nonetheless, I was quite annoyed when I noticed that Jangaron was not working correctly with Firefox 3.6. To be more precise, the mini game worked, and the settings UI worked, but starting the full game from the settings UI with sound enabled failed. The workaround was to
  1. play Jangaron mini only or
  2. switch off sound before starting the game from the UI.
Now that I found time to dig into the problem, the solution sounds somewhat familiar: browser detection was broken with Firefox 3.6! After patching that, everything now works fine again. So please spread the word to Firefox 3.6 users to go ahead and play Jangaron (again)!
The problem was in the browser detection code I copied back then from an old version of MooTools, which detects Gecko aka Firefox like so:
  if (window.document["getBoxObjectFor"] != null)
    return ENGINE_GECKO;

It is not really bad practice to use proprietary methods or properties to detect a browser, but as you can see in this case, it is not very future-safe. Because as browsers become more and more standards-compliant, especially these proprietary methods are likely to be removed (as in this case, see here). Or, as for example happened in case of Microsoft extensions like CONTENTEDITABLE, they are copied by other browsers, and thus also fail as a distinguishing criteria.
Whatsoever, since the only thing that came after GECKO was OPERA and UNKNOWN, I now ask for Opera first and consider everything else a Gecko and hope your exotic Linux browser won't mind.