1

Lets say I have the following game object hierarchy:

  • Board - The entire view of the game's board, made up of tiles.
  • Tile - A rectangular boundary within a board, made up of subtiles.
  • Subtile - A rectangular boundary within a tile.

A Board needs relative dimensions with respect to all of the contained Tile objects.

A Tile needs relative coordinates with respect to the containing Board.

A Subtile needs relative coordinates with respect to the containing Tile.

My current process is to define n Tile objects. Space them out x and y, such that x is the number of Subtile objects in a row and y is the number of Subtile objects in a column. Then, when I place Subtile objects, I just multiple the x or y by the containing Tile object's starting coordinate.

This process, so far, works well enough. However, to avoid complication and errors, I'd love to be able to simply lay out a Subtile object, where (0, 0) would be the top-left of the Tile object.

Without just abstracting my positioning a bit and adding classes for, say, SubtileVector or something, which would keep an additional variable for offset relative tile, is there an easier way to do this?

Likewise, when I want to see how big my board is and center my camera in the middle of it, I just end up calculating to that position. Is there any way to have my board always act as the containing box for these tiles, and be able to just do something like Board.Position.Center and get the exact center coordinates?

bdrelling
  • 830
  • 1
  • 10
  • 27

1 Answers1

2

Yes there is. You can make a board game object, parent it to tile game objects, who on their turn are parent to subtile objects:

Board, parent to Tile, parent to Subtile

The good news is you can use the relative coordinates of tile and subtile using using their

transform.localPosition
Rudolfwm
  • 689
  • 6
  • 15
  • Can't believe I was so blind that I missed localPosition on the 16th. This has been amazing for me since then, sorry I haven't commented. Accepting your answer since this the solution. – bdrelling Aug 26 '14 at 19:08