Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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? –  Joe Aug 10 '13 at 22:49
    
Yeah that should totally work :) –  RandyGaul Aug 10 '13 at 22:53
    
Awesome, thanks for the help! I'd up vote if I had rep. :-P –  Joe Aug 10 '13 at 23:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.