This experiment is a byproduct of another project I’m working on which involves flocking behaviors. I was trying to maximize performance by eliminating the use of arrays and replacing them with a linked list structure. Generally speaking, direct pointers should be much quicker in Actionscript than accessing data through an array. In practice, I didn’t notice any improvement in performance when using a linked grid and reverted back to a single array in order to reduce code complexity. A linked grid is probably worth exploring further for elements that will not be screen rendered; for my purposes the additional complexity did not seem to yield any benefits.
I put this demo together as a way to test the linked grid concept, but I liked the test enough that I cleaned it up visually and added mouse interaction. Below are a couple of screenshots followed by the actual Flash demo you can interact with.
Figure 1. There are 450 invisible points bouncing around the screen. As they come close to each other, a line is drawn connecting them.
Figure 2. Result of points being repelled by a mouse release action.
Figure 3. Clicking the mouse causes the points to head towards the mouse, while releasing quickly repels them.
Proximity grids are not new and have been utilized for a long time as an optimization technique in video games (search for “tile based collision detection” for further reading) and have also been explored thoroughly in Flash by developers such as Grant Skinner and Keith Peters (August 2005).