A new look at layered grids: setting up neighbors
The layered grid is a very generic type of grid. It allows you to stack a bunch of grids – of potentially different shapes – for any (usually 2D) point type. Because of this, it’s not possible for this type of grid to know which cells should be neighbors. The idea is for you to extend from this class, and override the GetAllNeighbors method.
This is quite simple to do. However, when I tried to make an example for a user, I found we forgot to make GetAllNeighbors virtual. We will add the fix to the next release, but if you want to use layered grids with your own neighbor configurations before then, we also included the fix in the example below. (We also made some small changes to LayeredPoint, and updated the LayeredGridTest example.)
The example shows how to extend from LayeredGrid in order to configure neighbors. The example scene has a grid like the one shown above; if you click on any cell, all the connected cells of the same color go white.
To check out the example:
- Import Grids 1.8 in a new project.
- Import the package below in project.
- Open the LayeredGridWithNeighbors scene. The same folder contains the BlockGrid code, which shows you how to override the GetAllNeighbors method.