layer_sprite_change


Using this function you can change the sprite resource assigned to a given sprite element on a layer. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and then supply a sprite index element asset will be changed. Note that if the sprite has sub-images then it will animate too (this can be controlled using the layer_sprite_index and layer_sprite_speed functions). Note that you can assign a value of -1 as the new sprite index and no sprite will be shown, although the element will still exist and can still be changed again later.


语法:

layer_sprite_change(sprite_element_id, sprite_index)


参数:

参数 描述
sprite_element_id The unique ID value of the sprite element to change
sprite_index The new sprite index to use


返回:

N/A(无返回值)


例如:

var s = layer_sprite_get_id(layer, global.Asset_sprite);
if layer_sprite_get_sprite(s) != spr_Nighttime
   {
   layer_sprite_change(s, spr_nighttime);
   }

The above code checks the sprite index of the element with the ID stored in the global variable global.Asset_sprite and if it is not "spr_Nighttime" then that sprite is assigned to the element.


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