layer_get_element_type


描述

You can use this function to get the element type for the given element. You supply the unique element ID value (for example, as returned the function that created the element or from the room editor) and the function will return one of the following constants (or -1 if the element does not exist or the ID value is erroneous):

常量 描述
layerelementtype_background The element is a background.
layerelementtype_instance The element is an instance.
layerelementtype_sprite The element is a sprite asset.
layerelementtype_tilemap The element is a tilemap.
layerelementtype_particlesystem The element is a particle system.
layerelementtype_tile The element is a legacy background tile (this is only valid for projects that have been imported from previous versions of GameMaker).

Note that this function is most useful when you have multiple different element types assigned to the one layer, and that you can get a list of all the elements on any given layer using the function layer_get_all_elements.


语法:

layer_get_element_type(element_id)


参数:

参数 描述
layer The unique ID value of the element to get the type of


返回:

Constant (see table, above) or -1 if element does not exist or is invalid


例如:

var a = layer_get_all_elements(layer);
for (var i = 0; i < array_length_1d(a); i++;)
   {
   if layer_get_element_type(a[i]) == layerelementtype_sprite
      {
      layer_sprite_destroy(a[i])
      }
   }

The above code gets the IDs for all the instance elements assigned to the layer of the instance running the code. The code then checks to see if any of the returned elements are sprite assets and if they then they are destroyed.


上一页: General Layer Functions
next: layer_get_x
© Copyright YoYo Games Ltd. 2018 All Rights Reserved