GMS 2 Test If Layer is Tile Layer

Perseus

Not Medusa
Forum Staff
Moderator
There's no way to get the layer type as a layer need not be limited to a single asset type dynamically. For instance, you can put a tilemap and a background on the same layer, so GM won't know what to return. You can, however, get the ID of an element from the layer and use layer_get_element_type to know what kind of elements are placed on the layer.
 
There's no way to get the layer type as a layer need not be limited to a single asset type dynamically. For instance, you can put a tilemap and a background on the same layer, so GM won't know what to return. You can, however, get the ID of an element from the layer and use layer_get_element_type to know what kind of elements are placed on the layer.
So there's no way to get only the layers (specifically id or name) in the room editor that are tile layers (have the 4 diamonds icon)? The room editor seems to give the impression that they are layers, with the different layer types. Do I have to name tile layers differently to find them in the Room Start event using layer_get_all() and step though all existing layers till I find the layers with "my_tiles" or some suffix I add to the name?
 

Perseus

Not Medusa
Forum Staff
Moderator
Yes, unlike the room editor you are not limited to a single asset type per layer, and can add multiple asset types to the same layer via code. Naming the layers that way should be the best option if you want to group layers together. You could use string_copy to get the prefix of the layer name and compare it with a given string.

Code:
var a = layer_get_all();
for (var i = array_length_1d(a) - 1; i > -1; i--) {
   var prefix = string_copy(layer_get_name(a[i]), 1, 4);
   if (prefix == "tile") {
      ds_list_add(tile_layers, a[i]);
   }
}
 
Top