• 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!

GML Getting Tilemap Without the Layer

L

Luka Radulovic

Guest
I'm putting in sound effects into my game currently and need a little help. I want to check which tilemap is below an object and based on that play a distinct sound.

For checking which tilemap is below I'm using the tilemap_get_at_pixel function. The first parameter is tilemap_element_id, which as far as I understand is the id of the specified tilemap. In any tutorials that I've seen they access this id with the function layer_tilemap_get_id which gets the tilemap that's set for that specific layer in the room.

In my game, there are rooms that have 2 or more different tilemaps (surfaces) that require different sounds to be played. Each of these tilemaps are in a different layer of course, as I don't see how I'd be able to put them into the same one.

Is there a way to check what tilemap is below an object without having to get the tilemap's id from its layer in the room?
 
A

Arconious

Guest
I want to check which tilemap is below an object and based on that play a distinct sound.
Hiyo! Just to be clear, I'm assuming you mean wanting to check an individual tile from a tilemap, right?

For checking which tilemap is below I'm using the tilemap_get_at_pixel function. The first parameter is tilemap_element_id, which as far as I understand is the id of the specified tilemap. In any tutorials that I've seen they access this id with the function layer_tilemap_get_id which gets the tilemap that's set for that specific layer in the room.

In my game, there are rooms that have 2 or more different tilemaps (surfaces) that require different sounds to be played. Each of these tilemaps are in a different layer of course, as I don't see how I'd be able to put them into the same one.
As far as I'm aware, a tilemap is tied to a layer in GMS 2. Any tilemap you create must be attached to a layer -- so assuming you set these layers up in the Room Editor, you should know the names of the layers that you're working with. There shouldn't be any issue with using layer_tilemap_get_id in that case to get the layers, and then check for the tiles you want, playing a sound if it matches a certain one.

Additionally, you can actually have multiple tilemaps per layer, if you create those tilemaps through code. The Room Editor only allows for a single tilemap assigned to an individual layer, but again that can be bypassed by adding tilemaps via code.
 
Top