Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
I'm assuming that you mean that you want to get the x and y values of a tile by referencing its index in the tilemap. In that case, there are two simple formulas for that.
To obtain the x value:
tile_x = tile_index % width_of_map
To obtain the y value:
tile_y = tile_index % height_of_map
In the event that you have the x and y values but you need the index, here's that formula as well:
tile_index = tile_x + (tile_y * width_of_map)
OR
tile_index = tile_y + (tile_x * height_of_map)
EDIT: I'm not entirely sure how the '%' operator translates into the GB-Z80's instruction set, so use with caution if you can't afford to lose speed.
Last edited by RainbowReich (2014-11-23 22:53:34)
Offline