I have a 2D tilemap that is generated in chunks consisting of 2x2 cells each. I can reference the chunk itself and get the index of each particular cell within the chunk. However, I'd like to also store the index of the first tile within that chunk, which is not automatically generated.
For example, clicking on the highlighted chunk would always produce "0", clicking on the next one would produce "2", and clicking on the one under it would always produce "20". Red numbers indicate the tile/cell's index. The yellow outline demonstrates an actual chunk.
Within the confines of the chunk, what is the best way to get 0, 2, 4, 6, 8, 20, and so on? The code that generates this is in Actionscript 3, and is a basic dual for loop.
EDIT:
I thought about it for a moment and decided to add in my index search code. I'm not entirely sure if this will help, especially since it is for finding individual cell index and not a particular index location in chunks.
public function mousePosistion():Number
{
var mouseColX: Number = 0;
var mouseColY: Number = 0;
mouseColY = Math.ceil(this.mouseY / 64);
mouseColX = Math.ceil(this.mouseX / 64);
var mouseIndex:Number = mouseColX + (20 * mouseColY);
return mouseIndex;
}
Note: It's formatted for the actual map which is at 20 width, not 10 as in the example.