Monthly Archive for January, 2010

Performant .live() in jQuery 1.4

So, jQuery 1.4 has very few new features that really make the upgrade worth it (though fixing the .val() on checkboxes and radiobuttons and implementing .detach() are both things that should have been done long ago), but the performance benefits are immense in some cases, so I decided to move the in-progress odkmaker project over.

One significant optimization I’ve been using with jQuery 1.3.2 for some time now was documented by Zach Leatherman — when you use .live() (and if you have a dynamic number of elements you should always be using .live() over .bind()), there’s actually a pretty horrible inefficiency inherent in the way it’s called. Read his post to get the in-depth explanation, but essentially you’re calling into the Sizzle engine to evaluate your selector, when really .live() only cares about the text of the selector. Zach’s method fixes this problem, but unfortunately due to some internal changes in jQuery 1.4, his brilliant method has stopped working.

Thankfully, the fix is pretty simple. The critically missing part is that jQuery objects now have a reference to their context, I suppose to ease use between frames. The resultant code is as follows:

    $.live = function(selector, type, callback)
        var obj = $([]);
        obj.selector = selector;
        obj.context = document;
        if (type && callback) {
  , callback);
        return obj;

So in the future, instead of

$('a[rel="modal"]').live('click', function(event)
    /* some code */

you should write

$.live('a[rel="modal"]', 'click', function(event)
    /* some code */

And thus you save the cost of iterating through the whole document for absolutely no reason.

This technique shaved off up to 7 seconds on pageload on a commercial-grade website I work on, so it would be a huge loss if it stopped working — it’s good news that it’s so easy to fix.

Review: VVVVVV


It’s no secret that the moment you make a 2D platforming game on a non-handheld platform, you’ll have my heart from the get-go. Releases in recent years have shown that unlike the 2D brawler genre, which had its heyday — looking at you, Streets of Rage — but is now dated and unenjoyable, the platforming genre has plenty left to say. Braid, Bionic Commando Rearmed, and New Super Mario Bros. Wii (despite its title) have shown that the affordances of modern hardware can allow for mechanics in platforming that are fresh, innovative, and which add new elements to the genre that were simply not possible or executed before 2D platforming was more or less abandoned twelve years ago. The sole exception here is perhaps Yoshi’s Island, which was far ahead of its time.

And then there was VVVVVV. Really, it doesn’t add anything that innovative to the genre. The gravity flipping mechanic has been done before by a million different online flash games, not to mention to an extent in Mega Man 5. Its 8-bit style means it doesn’t really push any boundaries graphically. It doesn’t even do that many things that wouldn’t have been possible on an NES. But damn if this isn’t a fantastic game.

Instead, the game takes advantage of the increase in horsepower to tighten up the mechanics. I’m old enough to remember when games were hard, but depending on the game any proportion of that difficulty could simply be assigned to general shoddiness. Poor hit detection, loose controls, and other quality issues often meant a thrown controller due to yet another death that seemed completely out of your control. I died 1155 times getting 100% in VVVVVV, and not once was it not my fault. That actually speaks volumes, I think, about just how tight the core mechanics are in this game.

Speaking of the core mechanics, VVVVVV‘s core mechanic — one might say gimmick — is actually immensely well done. Like Braid before it, the game takes a simple, perhaps overused mechanic (rewinding time in Braid and reversing gravity in VVVVVV), and examines it from different perspectives, adding different twists and poking at the result in interesting ways. As soon as you start to get the hang of each new mechanic in either game, it instantly yanks it away from you and replaces it with another one. The difference here is that while Braid focuses largely on puzzles and lateral thinking, VVVVVV is almost purely execution. The difficulty of the game ramps up pretty quickly, so even if you just go play the demo, you’ll find that not long after you’re introduced to a tripwire that reverses gravity the moment you hit it, you’ll come across rooms filled with them — and spikes.

There are a lot of spikes in this game.

There are, however, also a lot of checkpoints. These little diodes are scattered in enough places that you’ll never face one of gaming’s worst ruts: having to get through a lengthy easy part just to die at the real challenge over and over again. But don’t let their frequency fool you — this is still a hard game. It’s unforgiving in places. If you go for a full completion of the game, you’ll find yourself dying. A lot. One particular trinket took me around 500 deaths to nail (albeit it was 2 in the morning and I was exhausted at the time). And really, I wouldn’t have it any other way. It’s been a long time since I’ve played a game with the unforgiving spirit of the “old days,” and it’s frankly refreshing. Just be prepared to hear that death sound effect a lot.

Also be prepared to hear some fantastic music. This isn’t some chiptune nonsense, this is true 8-bit video game music. Actually, it’s probably not. There are some samples in there that belie its modern origin, but overall the spirit is there in spades.


The nostalgia isn’t limited to music, either: just look at this map and tell me it wasn’t ripped straight out of a Super Metroid.

If there’s one thing to complain about the game for, it’s its length. I hit 100% completion in the game in just about 2.5 hours. I’ve also played a lot of platforming games, so your mileage may vary. But for $15, I would really hope for a little more than that. There are plenty of possible mechanics left untouched that could have been interesting: areas that force gravity in a certain direction, or other objects that are also affected by your flipping, or perhaps even the ability to rotate gravity four ways rather than simply vertically. Perhaps these will be in VVVVVVV or something (yes, there is one more V in there), but it’s a shame they never saw the light of day in this one, considering how all-too-brief it is.

If you miss the old days as much as I do, and you enjoy the demo, I wouldn’t hesitate to buy this game full-price, sight unseen. If you don’t however, I can’t recommend spending the full $15 on it.