Gameboy Development Forum

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.

Ads

#1 2014-11-04 14:09:50

Crona
Member
From: Wisconsin
Registered: 2014-09-23
Posts: 58
Website

Is it possible to get the x and y position of a tile?

Just curious is it possible to get the x and y position of a sprite tile? It would be really easy to do even if its not, just wondering if I can save 2 variables.

Offline

 

#2 2014-11-23 22:51:44

RainbowReich
New member
Registered: 2014-11-23
Posts: 2

Re: Is it possible to get the x and y position of a tile?

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

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson