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?