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.

I'm making a game that uses a map which have tiles, corners and borders. Here's a graphical representation:

Tiles, Borders and Corners

I've managed to store tiles and corners in memory but I'm having troubles to get borders structured.

For the tiles, I have a [Map Width * Map Height] sized array. For corners I have [(Map Width + 1) * (Map Height + 1)] sized array. I've already made up the math needed to access corners from a tile, but I can't figure out how to store and access the borders from a single array.

Tiles store the type (and other game logic variables) and via the array index I can get the X, Y. Via this tile position it is possible to get the array index of the corners (which store the Z index).
The borders will store a game object and accessing corners from only border info would be also required.

If someone even has a better way to store these for better memory and performance I would gladly accept that.

EDIT: Using in C# and Javascript.

share|improve this question
Might want to post what language you are using. –  AttackingHobo Mar 19 '11 at 22:30
ImageShack seems to have deleted your image and replaced it with an ad banner. If you can, please reupload the image (or something equivalent) using the image upload button in the editor toolbar (which will upload it to Stack Exchange's imgur account). –  Ilmari Karonen Aug 17 at 19:03

2 Answers 2

up vote 3 down vote accepted

Look closely at your own illustration. What you've drawn here is a single two-dimensional array. Make an array of size [MapWidth*2+1, MapHeight*2+1] and store everything there. Elements where both coordinates are even will hold corners, where both coordinates are odd will hold tiles, and the rest will hold borders. You'd have to have a common base class for them, but I don't think that's a problem.

Of course, this is a little unintuitive, but adding a wrapper object around this array will solve it.

share|improve this answer

The borders will store a game object and accessing corners from only border info would be also required.

Keep a pointer/a reference to the corners in the border object? Do the same for tiles and borders?

Maintaining such a linear array of borders is definitely doable - you just need to separate vertical and horizontal borders. Then you can take all the borders of one direction and order them according to their x,y coordinates (it doesn't matter which axis is considered first), then simple integer algebra can be used to find the borders corresponding to a tile at coordinates (x,y). But still, I think you're on the wrong track. Consider using direct links between corresponding objects, as I noted above.

share|improve this answer

Your Answer


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.