• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

why is tilemap_get_at_pixel returning different values for same tile index?

kpenrose92

Member
Hello.

Tiles in my room with index 1 return 1 when i call tilemap_get_at_pixel at their location, but some of tiles with the same index return 1073741825.

Can anyone explain this to me?
 

rIKmAN

Member
Hello.

Tiles in my room with index 1 return 1 when i call tilemap_get_at_pixel at their location, but some of tiles with the same index return 1073741825.

Can anyone explain this to me?
Have the tiles not returning 1 been rotated, flipped or mirrored horizontally or vertically?

You will only get the tile index returned if the tile is unchanged, if you have flipped, rotated, mirrored or otherwise modified the tile with your own mask data then it will return the tile data blob. You can use the tile_get_* functions to extract the data from the tile blob as required (ie. get the index / flip / rotate / mirror values), and the tile_set_* to set the same data in the blob.

From the manual:
IMPORTANT! If the tiles in the tile map have been unchanged (ie: they are not rotated or flipped etc...), then the return value of the tile set data will be exactly equal to the index of the tile on the tile set. So you can create "collision maps" of tiles using one tile at index 1 in the tile set - for example - then use this function to check for 1 or 0 (an empty tile) to calculate collisions.
 

kpenrose92

Member
Have the tiles not returning 1 been rotated, flipped or mirrored horizontally or vertically?

You will only get the tile index returned if the tile is unchanged, if you have flipped, rotated, mirrored or otherwise modified the tile with your own mask data then it will return the tile data blob. You can use the tile_get_* functions to extract the data from the tile blob as required (ie. get the index / flip / rotate / mirror values), and the tile_set_* to set the same data in the blob.

From the manual:
Thank you. I do not believe the tiles have been flipped or rotated, but they were added using the paint bucket tool, maybe that had something to do with it.

Anyway, I solved my particular problem by using tile_get_index on the data i extracted with tilemap_get_at_pixel and now it works perfectly. Thanks!
 

rIKmAN

Member
Thank you. I do not believe the tiles have been flipped or rotated, but they were added using the paint bucket tool, maybe that had something to do with it.

Anyway, I solved my particular problem by using tile_get_index on the data i extracted with tilemap_get_at_pixel and now it works perfectly. Thanks!
The paint bucket shouldn't have any effect as by default it'd be painting unchanged tiles, however it's possible that you toggled one of the flip/rotate/mirror buttons by accident when painting the tiles and the ones returning the blob data have actually been modified from default without you realising and without it being too visually obvious.

Glad you got it working with the functions I mentioned anyway.
 
Top