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)

  this.tiles = [];
  this.chunks = [];

  //Establish tiles
  for(var x = 0; x < WIDTH; x++)
    var col = [],
        ch_x = Math.floor(x/TPC);


    for(var y = 0; y < HEIGHT; y++)
      var tile = new Tile(x, y),
          ch_y = Math.floor(y/TPC);





Even some basic advice on my data struct would be much appreciated.

  • \$\begingroup\$ Any tips for improving my question? \$\endgroup\$ Jul 7, 2014 at 1:35

1 Answer 1


I don't think speed is a huge issue between your different methods so you might go with whichever approach you think is easiest. I would absolutely choose to access the arrays differently and not store pre-rotated versions of them.

For rotating one chunk: normal rotation gives you array[x][y] -90 degrees would give you array[WIDTH-1-y][x] 180 degrees would give you array[WIDTH-1-x][HEIGHT-1-y] 90 degrees would give you array[y][HEIGHT-1-x]

I would recommend somehow putting chunk access behind a layer of abstraction. Just ask for tiles on the map relative to the player and change access to the tiles based on the rotation.

As for improving your question, I don't think that's anything anyone can answer. You'd have to consider what motivates people to answer questions. Personally, I almost didn't answer because the question seems too simple and I don't know enough to understand what is giving you trouble so I don't feel that I can help.

  • \$\begingroup\$ Thank you!! Good advice all around, I really appreciate you working through my vagueries :] I'll ask better next time because of it, I'm sure! --- P.S. Seeing the rotation laid out like that really made a lot click for me, and "putting chunk access behind a layer of abstraction" really drove home some other realizations. Thanks again. \$\endgroup\$ Jul 22, 2014 at 0:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .