Skip to content

Screenshotting ​

The following methods allow taking screenshots of initialized rooms.

Screenshots can be used in a variety of ways, like displaying previews in a level selection menu, capturing layouts for notes or level design, or previewing rooms in the world before loading them in.

IMPORTANT

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

WARNING

Screenshotting methods return new sprites created by sprite_create_from_surface(). Make sure to keep track of them and delete them using sprite_delete() when they're no longer needed.

.Screenshot() ​

RoomLoader.Screenshot(room, [xOrigin], [yOrigin], [xScale], [yScale], [flags] ➜ Asset.GMSprite

Takes a screenshot of the given room. If specified, assigns the optional Origin and scale to the created sprite and filters the captured elements by the given Flags.

Returns the created Asset.GMSprite.

ParameterTypeDescription
roomAsset.GMRoomThe room to take a screenshot of
[xOrigin]RealThe x sprite Origin [Default: State.XOrigin if set, or ROOMLOADER_DEFAULT_XORIGIN]
[yOrigin]RealThe y sprite Origin [Default: State.YOrigin if set, or ROOMLOADER_DEFAULT_YORIGIN]
[xScale]RealThe horizontal sprite scale [Default: State.XScale if set, or 1]
[yScale]RealThe vertical sprite scale [Default: State.YScale if set, or 1]
[flags]Enum.ROOMLOADER_FLAGThe flags used to filter captured elements [Default: State.Flags if set, or ROOMLOADER_FLAG.ALL]
js
// Takes a screenshot of rmExample with a Middle Center origin, captures only
// Tilemaps and Sprites:
var _flags = ROOMLOADER_FLAG.TILEMAPS | ROOMLOADER_FLAG.SPRITES;
screenshot = RoomLoader.Screenshot(rmExample, 0.5, 0.5, _flags); 
js
// Takes a screenshot of rmExample with a Middle Center origin, captures only
// Tilemaps and Sprites:
screenshot = RoomLoader.MiddleCenter().Tilemaps().Sprites().Screenshot(rmExample); 

.ScreenshotPart() ​

RoomLoader.ScreenshotPart(room, left, top, width, height, [xOrigin], [yOrigin], [xScale], [yScale], [flags]) ➜ Asset.GMSprite

Takes a screenshot part of the given room, with the captured area defined by left, top, width and height parameters, just like draw_sprite_part(). If specified, assigns the optional Origin and scale to the created sprite and filters the captured elements by the given Flags.

Returns the created Asset.GMSprite.

ParameterTypeDescription
roomAsset.GMRoomThe room to take a screenshot of
leftRealThe x position on the sprite of the top-left corner of the area to capture (0–1 percentage)
topRealThe y position on the sprite of the top-left corner of the area to capture (0–1 percentage)
widthRealThe width of the area to capture (0–1 percentage)
heightRealThe height of the area to capture (0–1 percentage)
[xOrigin]RealThe x sprite Origin [Default: State.XOrigin if set, or ROOMLOADER_DEFAULT_XORIGIN]
[yOrigin]RealThe y sprite Origin [Default: State.YOrigin if set, or ROOMLOADER_DEFAULT_YORIGIN]
[xScale]RealThe horizontal scale to create the sprite at [Default: State.XScale if set, or 1]
[yScale]RealThe vertical scale to create the sprite at [Default: State.YScale if set, or 1]
[flags]Enum.ROOMLOADER_FLAGThe flags used to filter the captured elements [Default: State.Flags if set, or ROOMLOADER_FLAG.ALL]
js
// Takes a screenshot of the top-left quadrant of rmExample with a Middle Center origin,
// scales it up by a factor of 2, and captures only Instances:
screenshot = RoomLoader.ScreenshotPart(rmExample, 0, 0, 0.5, 0.5, 0.5, 0.5, 2, 2, ROOMLOADER_FLAG.INSTANCES); 
js
// Takes a screenshot of the top-left quadrant of rmExample with a Middle Center origin,
// scales it up by a factor of 2, and captures only Instances:
screenshot = RoomLoader
.MiddleCenter().Scale(2).Instances()
.ScreenshotPart(rmExample, 0, 0, 0.5, 0.5);