This function can be used to retrieve the unique ID value of the sprite element on a layer. You supply the layer ID (which you get when you create the layer using layer_create() or when you use the layer name along with layer_get_id()) and the name of the asset as defined in the IDE asset properties. The function will return the ID value associated with that sprite element on the layer. Note that this function is specifically designed for use with sprites that have been added in the IDE on an asset layer, as if you add a sprite to a layer through code using the function layer_sprite_create, then it will return the unique ID for the sprite element added (and the new element will have no name).
layer_sprite_get_id(layer_id, asset_name)
参数 描述 layer_id The unique ID value of the layer to target asset_name The unique name of the asset on the layer as defined in the room editor
Sprite element ID value (Real)
var lay_id = layer_get_id("Assets_trees");
var back_id = layer_sprite_get_id(lay_id, "gfc_Trees");
layer_sprite_change(back_id, spr_Trees_Winter);
The above code will get the layer ID for the layer named "Assets_trees" and then use that to get the ID of the sprite element "gfc_Trees" on that layer. This ID is then used to change the element sprite.