layer_set_target_room


描述

When you call this function you are telling GameMaker Studio 2 that all further layer functions should be applied to the given room. In this way you can procedurally change or generate layers and layer contents in a room that is not the current room. When you are finished adding layers or layer elements to a room, call the function layer_reset_target_room to reset the room target (or call this function again with a room argument of -1).

WARNING! While targeting another room, you can use all the regular layer functions except you cannot create instances using instance_create_layer or instance_create_depth, nor will the layer function layer_add_instance be available.


语法:

layer_set_target_room(room)


参数:

参数 描述
room The room to target for all further layer functions


返回:

N/A(无返回值)


例如:

layer_set_target_room(rm_Game);
var l = layer_get_id("SpriteAssets");
repeat(50)
   {
   layer_sprite_create(l, random(room_get_width(rm_Game)), random(room_get_height(rm_Game)), spr_Trees);
   }
layer_reset_target_room();

The above code sets the target room to the room "rm_Game" and then gets the layer ID for the layer called "SpriteAssets" in that room. This layer ID is then used to add 50 random sprite assets to the layer, before the layer target is reset to the current room.


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