Skip to content

Loading

IMPORTANT

Rooms can only be loaded if their data has been initialized. Make sure to Initialize the data for any room you intend to load beforehand, or the game will crash.

.Load()

RoomLoader.Load(room, x, y, [xOrigin], [yOrigin], [flags])Struct.Payload or Undefined

Loads the given room at the given coordinates and origin, filtered by the given flags.

ParameterTypeDescription
roomAsset.GMRoomThe room to load
xRealThe x coordinate to load the room at
yRealThe y coordinate to load the room at
[xOrigin]RealThe x origin to load the room at. [Default: ROOMLOADER_DEFAULT_XORIGIN]
[yOrigin]RealThe y origin to load the room at. [Default: ROOMLOADER_DEFAULT_YORIGIN]
[flags]Enum.ROOMLOADER_FLAGThe flags to filter the loaded data by. [Default: ROOMLOADER_DEFAULT_FLAGS]
js
// Loads rmLevelCastle at arbitrary coordinates:
RoomLoader.Load(rmLevelCastle, someX, someY); 

// Loads rmLevelForest centered in the room: 
var _x = room_width / 2;
var _y = room_height / 2;
RoomLoader.Load(rmLevelForest, _x, _y, 0.5, 0.5); 

// Loads rmLevelCliff's Sprites and Tilemaps at the bottom-right corner of the room
// and stores the returned instance of Payload in a variable to be cleaned up later:
var _flags = ROOMLOADER_FLAG.SPRITES | ROOMLOADER_FLAG.TILEMAPS;
roomPayload = RoomLoader.Load(rmLevelCliffs, room_width, room_height, 1, 1, _flags); 

.LoadInstances()

RoomLoader.LoadInstances(room, x, y, layerOrDepth, [xOrigin], [yOrigin], [xScale], [yScale], [angle], [multScale])Array of Id.Instance

Loads all instances from the given room at the given coordinates and origin, with optional scaling and rotation transformations.

ParameterTypeDescription
roomAsset.GMRoomThe room to load instances from
xRealThe x coordinate to load instances at
yRealThe y coordinate to load instances at
layerOrDepthId.Layer or String or RealThe layer ID, layer name, or depth to create instances on
[xOrigin]RealThe x origin to load the room at. [Default: ROOMLOADER_DEFAULT_XORIGIN]
[yOrigin]RealThe y origin to load the room at. [Default: ROOMLOADER_DEFAULT_YORIGIN]
[xscale]RealThe horizontal scale transformation
[yscale]RealThe vertical scale transformation
[angle]RealThe angle transformation
[multScale]BoolScale instances with xScale/yScale? [Default: ROOMLOADER_INSTANCES_DEFAULT_MULT_SCALE]
[addAngle]BoolRotate instances with angle? [Default: ROOMLOADER_INSTANCES_DEFAULT_ADD_ANGLE]
js
// Loads instances from rmLevelPartBottom at the bottom-right corner of the room:
RoomLoader.LoadInstances(rmLevelPartBottom, room_width, room_height, depth, 1, 1); 

// Loads a layout of props to fill the size of the current room, while keeping instance scale unaffected:
var _room = rmProps;
var _xscale = room_width / RoomLoader.DataGetWidth(_room);
var _yscale = room_height / RoomLoader.DataGetHeight(_room);
RoomLoader.LoadInstances(_room, 0, 0, depth, _xscale, _yscale, 0, false); 

// Loads a random arrangement of collectibles randomly rotated at the center of the room:
var _room = choose(rmCollectibles01, rmCollectibles02, rmCollectibles03);
var _x = room_width / 2;
var _y = room_height / 2;
var _angle = random(360);
RoomLoader.LoadInstances(_room, _x, _y, depth,,, _angle); 

// Loads a random enemy layout in front of the player and stores their IDs in the loadedEnemies array:
var _room = script_execute_ext(choose, enemyLayoutRooms);
var _offset = 200;
var _x = objPlayer.x + lengthdir_x(_offset, objPlayer.angle);
var _y = objPlayer.y + lengthdir_y(_offset, objPlayer.angle);
var _angle = objPlayer.angle - 90;
loadedEnemies = RoomLoader.LoadInstances(_room, _x, _y, depth,,, _angle); 

.LoadTilemap()

RoomLoader.LoadTilemap(room, x, y, sourceLayerName, targetLayer, [xOrigin], [yOrigin], [mirror], [flip], [angle], [tileset])Id.Tilemap

Loads a tilemap from the given room and layer at the given coordinates and origin. Creates it on the targetLayer with optional mirroring (flip on the x axis), flipping (flip on y axis) and rotation transformations, and tileset.

  • The loaded tilemap is rotated first, then mirrored and flipped.
  • Angle is internally wrapped around 360 degrees and snapped to a 90-degree increment.
  • When using a custom tileset, make sure that tiles on both tilesets are perfectly aligned, or you'll get a mess of misplaced tiles.
ParameterTypeDescription
roomAsset.GMRoomThe room to load a tilemap from
xRealThe x coordinate to load the tilemap at
yRealThe y coordinate to load the tilemap at
sourceLayerNameStringThe source layer name to load a tilemap from
targetLayerId.Layer, StringThe target layer to create the tilemap on
[xOrigin]RealThe x origin to load the tilemap at. [Default: ROOMLOADER_DEFAULT_XORIGIN]
[yOrigin]RealThe y origin to load the tilemap at. [Default: ROOMLOADER_DEFAULT_YORIGIN]
[mirror]BoolMirror the loaded tilemap? [Default: false]
[flip]BoolFlip the loaded tilemap? [Default: false]
[angle]RealThe angle to load the tilemap at. [Default: 0]
[tileset]Asset.GMTilesetThe tileset to use for the tilemap. [Default: source]
js
// Loads a tilemap from the "TilesFloor" layer in rmCasinoDetails,
// creates it in the centered in the room on the layer with the same name,
// and randomly mirrors and flips it:
var _x = room_width / 2;
var _y = room_height / 2;
var _layer = "TilesFloor";
var _mirror = choose(true, false);
var _flip = choose(true, false);
floorTilemap = RoomLoader.LoadTilemap(rmCasinoDetails, _x, _y, _layer, _layer, 0.5, 0.5, _mirror, _flip); 

// Loads a tilemap from the "TilesWalls" layer in rmChunkSpecial01,
// creates it on the newly created collision layer, assigns the tsWallsCollision tileset to it
// and stores its ID in the collisionTilemap variable:
collisionLayer = layer_create(0, "Collision");
collisionTilemap = RoomLoader.LoadTilemap(rmChunkSpecial01, 0, 0, "TilesWalls", collisionLayer, 0, 0, false, false, 0, tsWallsCollision);