Category Archives: Javascript

The best kind of script

Closures with self-invoking functions

Just a quick note-to-self… I’m a big fan of using self-invoking anonymous functions to keep stuff out of the global namespace, but I forgot that they are also nifty for keeping variables in scope via closures. Here’s the problem… Let’s say with have an array that we’d like to populate with functions. The functions simply [...]

Using jQuery on JavaScript objects (Part 1)

Today I was trying to decouple some JavaScript classes in a game prototype I’ve been working on. I didn’t want to get into implementing some kind of interface behaviour, and so I thought about a simple Observer pattern. There are a bunch of solutions around the tubes (and indeed I’ll probably use one of them) [...]

Smoking Canvas

On the way to work today I remembered an old trick to create a “fire” effect: you randomly assign a colour to the pixels on the bottom row of the screen (in the same hue) and for each row above it take the average of the 3 pixels immediately below it, and 1 pixel that [...]

Springs with Canvas

Even more Canvas vs Maths fun! This JavaScript demo vaguely emulates some spring physics. There are 10 linked points – each of whose acceleration is determined by the distance to the spring in front of them. A nice curve drawn between each point using the quadraticCurveTo command. And it sure makes some perdy patterns. The [...]

3D with HTML5 Canvas: Part 2

Part 2! Unbelievable, my attention span is expanding in my old age… Today we are going to look at building on the 3d starfield of Part 1 by moving from dots to lines! By the end of this tutorial, we’ll have a floating cube demo that we can scale and translate in 3D space. Use [...]

JavaScript games for iPhone

The good Mr Craig Sharkie (URL pending…) pointed me to a JavaScript game that was designed to run on the iPhone. Being a copycat, I decided to port my recently un-earthed platform game to be iPhone-friendly. Due to a serendipitous accident, the game was already 320×480 pixels – so all that was required was to [...]

Blobby physics thing

Add ForceJointsPointsOutlineFill Auto

More javascript madness

Presenting yet another blast-from-the-javascript-past, “Some Adventure-y Guy: The Platformer!”. Navigate your way around the treacherous pits of, err, darkeness in search of the mystical sack of money I copied from Pitfall…

Javascript game: Deamons Of Space

Another piece of JavaScript magic from the 2003 archives: I gave it a quick once-over to get it up and running in Firefox… though now it might not work in anything else, but there you go. Like all my creations, the controls are damn hard to get used to – I don’t know what I [...]