Legacy GM [SOLVED] How to find which tile at a position

Steneub

Member
I would like to know what tile is at a given position.
Code:
if (mouse_check_button_released(mb_left)) {    
    //d is defined as depth of tiles
    var tile = tile_layer_find(d, mouse_x, mouse_y);    
    if (tile != -1) {        
        show_debug_message(string( tile_get_background(tile) ));
    }
}
This is helpful in finding the tile and which Background, but it doesn't give me enough information about the tile itself. I want to know which tile is being indexed here. If I have two tiles next to eachother which use, say, the grass tile, the tile value is unique between them.

When I click two adjacent positions that use the same tile from the same background asset, these values appear in my console:
Code:
10000000
10000001
Which I've discovered these values are what are generated sequentially in the order in which they were placed (starting with 10000000 apparently).

If I could even get the x and y offset into the background asset, that would still be helpful enough to do some simple math to determine which tile is at the position.

Any help would be appreciated.
 

Steneub

Member
I'm continuing to dig, check this out
Code:
<tile bgName="tileset2" x="24" y="24" w="8" h="8" xo="0" yo="16" id="10000029" name="inst_D5885631" depth="1000000" locked="0" colour="4294967295" scaleX="1" scaleY="1"/>
This is pulled from the room file in a text editor.
  • x,y are for roomspace;
  • w,h are for the size of the tile; and
  • xo,yo are the offset where that tile is pulled from in the background asset source
If I could extract this xo and yo from the tile id, I might be well on my way to solving this problem
 

Steneub

Member
After poring through the documentation again (for the nth time), I found what I was looking for! The not so intuitively named get_tile_left and get_tile_top

Together, these functions will return the offsets within the Background asset for the given tile. Here is my updated script to show how I'm doing this
Code:
if (mouse_check_button_released(mb_left)) {   
    var tile = tile_layer_find(d, mouse_x, mouse_y);   
    if (tile != -1) {       
       
        var left = tile_get_left(tile) / TILE_SIZE;
        var top = tile_get_top(tile) / TILE_SIZE;      
       
        show_debug_message("("+ string(left) + ", " +string(top) +")"); 
    }
}
I was able to figure out my problem and I'm trying to be responsible by showing the solution instead of fading into obscurity

 
Top