Rotating a view of a chunked 2d tilemap
- by Danie Clawson
I'm working on a top-down (oblique) tile-based engine. I would like for the tiles to have a definable height in the world, with Characters being occluded by them, etc.
This has led to a desire to be able to "rotate" the view of the world, even though I'm using all hand-drawn graphics and blitting.
Therefor, I need to rotate the actual world itself, or change how the Camera traverses these arrays.
How can, or should, I create individual rotations of 90 degrees, when I have multi-dimensional arrays?
Is it faster to actually rotate the array, to access it differently, or to create pre-computed accessor(?) arrays, something like how my chunks work?
How can I rotate an individual chunk, or set of chunks?
Currently I establish my tile grid like this (tile height not included):
function Surface(WIDTH, HEIGHT)
{
WIDTH = Math.max(WIDTH-(WIDTH%TPC), TPC);
HEIGHT = Math.max(HEIGHT-(HEIGHT%TPC), TPC);
this.tiles = [];
this.chunks = [];
//Establish tiles
for(var x = 0; x < WIDTH; x++)
{
var col = [],
ch_x = Math.floor(x/TPC);
if(!this.chunks[ch_x])
this.chunks.push([]);
for(var y = 0; y < HEIGHT; y++)
{
var tile = new Tile(x, y),
ch_y = Math.floor(y/TPC);
if(!this.chunks[ch_x][ch_y])
this.chunks[ch_x].push([]);
this.chunks[ch_x][ch_y].push(tile);
col.push(tile);
}
this.tiles.push(col);
}
};
Even some basic advice on my data struct would be much appreciated.