AS3 Particle System/Color Transforming Flash Game

July 20th, 2009

Recently I was going back through some past projects and experiments, and I came across a particle system I had played with when making the jump from AS2 to AS3.  I ended up digging into the code and fiddling with it – a bit here, a bit there – until some kind of weird game/toy emerged.

Basically, your goal is to match the colour of the particles emerging from your mouse to the colour of the background in the center. You do this by adding or subtracting red, green, and blue from the colour of the particles, mousing over the colours in the left column to add them, and in the right column to subtract them. When one of the individual colours gets close to being the right value, the respective blobs will start to pulse. Match the colour to gain a point, and the target colour will change. You have until the target colour disappears to match as many as you can.

This project utilised the very useful argbToHex function for converting an ARGB (alpha, red, green blue) value into a hex (hexadecimal) value for use in a colorTransform. For reference, the function is simply:

function argbToHex(a:Number, r:Number, g:Number, b:Number){
  return a<<24|r<<16|g<<8|b;
}

When calling this function, you just supply it with the alpha, red, green, and blue values, and the function uses the bitwise left shift operator (<<) to add them up into a valid hexadecimal value. For anyone interested, I plan to write a bit more on the basics of this particle system (and particle systems in general) in the future, as I think they can be a fun introduction to OOP.

Leave a Reply