Category Archives: Javascript

The best kind of script

One-line array wrap

I like this lil’ one-liner for wrapping around an array forward, or backwards. Given an array, with a current index, you want to move either to the next item, or the previous one. Here’s the setup: var a = [“alice”, “bob”, “charlie”], current = 0; // start with “alice”, direction = Math.random() < 0.5 ? […]

Into the third dimension

My loyal long-term readers (by whom I mean Anton) would know my technological aesthetic bent strongly favour the 1980s. Seeing as the third dimension was not discovered until 1992, I have thus far had little inclination to bother with it. But things have changed: now that the 90s are suitably retro I feel it’s finally […]

ZMORE: a game in 48 hours

Here’s my entry for Ludum Dare #26, on the theme Minimalism.

DHTML Lemmings: an awesome hack

That image is the punchline to the question I awoke with in the middle of last night: “How the FLIPPIN’ ‘ECK did that guy do destructible terrain for DHTML Lemmings… in 2004?!!!”. I lay there for some time as thoughts raced through my mind: There was no canvas element in 2004. No WebGL. In fact, […]

Short function syntax is here!

It’s happened. It’s finally happened. Short function syntax is here! At least, if you’re running the nightly version of Firefox (which I am now, due to my promise to adopt the first browser to introduce short function syntax). Short function syntax replaces the lengthy function keyword with a symbol =>, and the almost-as-lengthy return keyword […]

#Random Hex colour

Want a random colour between white and black? “#” + (Math.random() * 0xffffff | 0).toString(16) That is all. [Update: after I posted this I thought… i bet this has been done a zillion times already. It was, and by Paul Irish in 2009 no less. Additionally – it doesn’t work. The best looking one there […]

Live editing for game development

Here’s a small demo on how I’ve been using Chrome’s “live editing” features to speed up my development workflow. Chrome let’s you modify currently loaded files on the fly – so you can tweak settings and test code in real time. Don’t forget to keep an eye on the development of my up-and-coming waterski odyssey: […]

CoffeeScript: tell me how you feel about it

[update: wow, amazing response so far! I’ll start collating the data and get you all some findings soon.] Hey chaps, I’m canvasing general opinions and understanding about CoffeeScript as research for an up-n-coming book. There seems to be some pretty strong thoughts on the matter amongst the people I’ve talked to in person, and I’m […]

Colourising sprites in Canvas – part 2

And we’re back! In part one we looked at setting up a tinted palette for drawing our 8-bit masterpieces to canvas. Here’s what we’re going for today: rendering colourised sprites and tiles. We’ll be loading in our (ok, Notch’s) 4-color sprite sheet and rendering tiles from it with our chosen colours.