Saturday 17 December 2011


As I've used it in two posts I should mention what wonderfl is. It's simply one of the best resources available for Flash developers, in particular ActionScript programmers. It lets developers upload and run ActionScript, for testing or to demonstrate it. Code on the site can be modified, even if you did not write it, by creating a copy (or a 'fork') and working on that. Editing and testing all takes place in the browser, making it often much quicker than setting up a similar project in Adobe Flash CS or a similar environment.

Friday 16 December 2011

A faster random

Although ActionScript has its own random number function, Math.random(), like most library calls it is not especially fast. But it is easy to replace, to provide a significant speed up, as well as make it easier to do other optimisations.

The basic idea is very simple: instead of calling Math.random()while the game is running call it a number of times at startup to populate a list, then at runtime pull values out of that list. This would not work in all games: it might produce predictable or repetitive outcomes in some cases. But in games where random numbers are used for effect or to provide some variability in a number of ways it is often indistinguishable from Math.random() (which is not truly random anyway).

Thursday 15 December 2011

One decimal place

This is a small function I wrote to print Numbers to one decimal place. Most user-visible values used in Bug Tunnel Defense were whole numbers and so were stored as int. But a few needed more precision and so were stored as Number. So they did not overflow their TextField they were displayed to one decimal place, using this function.

Wednesday 14 December 2011

Bug Tunnel Defense release notes

I discussed these in detail on the blog I ran for Bug Tunnel Defense's release. Rather than repost those posts separately I'll summarise them, with links to the originals.

Tuesday 13 December 2011


The Matrix class in Flash is a two-dimensional matrix, used to draw and display objects on the stage. It is difficult to avoid as it is needed for some calls, especially the draw function of the BitmapData class. The Matrix if something is to be drawn without moving, but generally it's required.

The simplest use is to offset something as it is drawn. I find this is also the most common use, so it's useful to have a quick way to do it. Here's an example of that, drawing a wall block into a layer based on its grid position.