Gaming Your Way

May contain nuts.

A bit more of the same

Well I carried on working on the GWars effect last night, and discovered quite a few things.

The example from yesterday used a raster line plotter, but I tried it with the Flash drawing API ( Which uses Flash's vector plotter ) and it crapped all over it in terms of speed. I was surprised but I guess it's 'cause the dAPI works on a "hardware" level.

Next up was to look at Geometry Wars itself, where I realised that the grid was made up of a load of dots rather than lines. Back to the code, I used the dashTo prototype ( An example of that can be seen here ) and got a nasty drop in speed. No shock there really. Then it dawned on me that the raster line drawer could be kinda handy here, after all it's just a loop and some setPixels, if we're skipping pixels to make a dotted line then it'll reduce the length of the loop.

Sweet, ran a lot quicker.

Next up was a bit of a lucky one. I had a bitmap which I copied the grid to every couple of frames and ran a ColorMatrixFilter on it to fade it down ( By reducing the alpha every frame ), and where I was putting a surround on the screen and positioning things I screwed up the alignment of this bitmap, so I could see the lines slightly offset. It didn't take long to align it so it was offset by half a grid position on the x/y, hey presto, twice as many lines and for no more hit than it was running at anyway.

Time to drop a player sprite in there ( My very first as3 one, I imagine there will be more ). I really liked the control system in neon2, where holding ctrl down stopped the player ship so you could just rotate and shoot, and as3 just gave it to me for free.
When using a MouseEvent.MOUSE_DOWN event listener, the event which is called has an arg passed to it. This arg has all types of interesting goodies in it, one of which is a boolean ctrlKey flag. So adding the keyboard control I wanted took about 3 lines, and from a cpu point of view it's a freebie ( Ok, at the hardware level Flash is scanning the key, but it does anyway on a MOUSE_DOWN event so it's not like I'm polling the keys seperately ).

Want to see it ? Yeah you do.

GWars_v2.swf (37.69 KB)

Squize.
Comments are closed