2
\$\begingroup\$

Games like RollerCoaster Tycoon allow you to rotate the view at 90 degree intervals. I'm wondering how I could apply this to a game I'm making. I'm using MonoGame... but I'm wondering more if anyone could explain the theory behind the transformation rather than something language specific.

This video is exactly what I want to accomplish: http://youtu.be/qitkgiP13gw?t=15s

Basically all my tiles are in a 2D grid, and I just convert each X and Y to isometric for drawing. I'm assuming the transformation might be straight forward since it's a matter displaying the tiles with the right transformation.

Any help is greatly appreciated!

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

Pretty sure the easiest way to do rotation like this is to actually hard-code a simple rotation of the underlying array representing the isometric world.

Say you have a small array representing tiles, something like this (9 tiles total):

[0 2 0]
[1 0 4]
[1 0 1]

Rotate 90 degrees clockwise could be done by swapping the numbers in the array around:

[1 1 0]
[0 0 2]
[1 4 0]

You can do this pretty easily by creating a temporary tile-array, copy over the data in a rotated fashion, then swap the new array for the old tile-array, and delete the old array.

Then your tile engine itself can just render your new tile-array however it currently is laid out in memory. There's no graphical rotation involved in the video you've shown, but instead a clever trick like this is used.

Alternatively you can read from your tile-array in a different order, instead of creating an entire new array. Instead of reading in your array linearly throughout memory, you can traverse your tile-array and render it from a different configuration. This is similar to creating an entire new tile-array, but is swapping reading algorithms instead of swapping tile-arrays. This would definitely be more efficient, but harder to code.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for the answer! I think what I'm going to do is change my tiles from an ArrayList to a 2D array, since the map size doesn't change. That way I can just calculate the X and Y based on the position they are in the array. And when I want to rotate the world, I can just rotate the array. Does that sound like a good course of action? \$\endgroup\$
    – Joe
    Commented Aug 10, 2013 at 22:49
  • \$\begingroup\$ Yeah that should totally work :) \$\endgroup\$
    – RandyGaul
    Commented Aug 10, 2013 at 22:53
  • \$\begingroup\$ Awesome, thanks for the help! I'd up vote if I had rep. :-P \$\endgroup\$
    – Joe
    Commented Aug 10, 2013 at 23:48

You must log in to answer this question.

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