RUSTICDOCSSearch documentation

Native game windows

Use game.window to change a desktop game's presentation. Use game.scene.openInWindow to run a second scene alongside the main scene. These APIs work in the editor's native New Window and Standalone play modes and in native desktop packages. Embedded Play, website exports and Android return false from game.window.isSupported(). Guard shared scripts with that check.

Open a scene in its own window

  1. Save your main scene as Main. Save a separate scene named HUD at scene/hud.scene, with an active camera and some visible objects.
  2. Create a Lua 5.4 script and add it to Main as a Scene Startup Script. Return a behavior table with a Start callback. Save the script and both scenes.
  3. Open Main and launch New Window play. The main window should display the Main scene at 16:10. A second, undecorated window titled HUD should display its own scene at 4:3.
lua
return {
  Start = function()
    if not game.window.isSupported() then return end

    game.window.configure({
        mode = "windowed",
        aspectRatio = {16, 10},
        minSize = {640, 400},
        maxSize = {1600, 1000}
    })

    local hud = game.scene.openInWindow("scene/hud.scene", {
        mode = "borderlessWindowed",
        aspectRatio = {4, 3},
        minSize = {320, 240},
        maxSize = {800, 600}
    })
    print("HUD window ID", hud)
  end
}

Each displayed scene runs its own scene and object scripts and receives input from its own focused window. Global startup scripts remain tied to the main scene. game.scene.getActive() reports the scene in the main window. Choose a scene that is currently undisplayed when opening a second window. To move a secondary scene into the main window, close its secondary window before calling game.scene.switchTo.

Window controls

CallBehavior
game.window.isSupported()Returns whether the runtime owns native game windows.
game.window.current()Returns the calling scene's window ID. The main window ID is 0.
game.window.configure(options, window?)Applies the supplied options to the scene displayed in the target window.
game.scene.setWindowOptions(scene, options)Stores options for a loaded scene or a saved scene name or project-relative path. A saved scene need not be opened first. Settings apply whenever the scene is displayed during this session.
game.scene.openInWindow(scene, options?)Loads the scene if necessary, requests a secondary window and returns its ID. Optional settings update that scene's existing options.
game.window.minimize(window?)Requests that the OS minimize the target window. Simulation continues.
game.window.restore(window?)Requests that the OS unminimize the target window.
game.window.close(window?)Closes a secondary window or ends the game normally when targeting the main window.

Except for isSupported, these APIs require native game play. Omit the window ID to target the calling scene's window. Global scripts default to the main window. A script in an undisplayed scene must pass an explicit ID. Pass 0 from a secondary scene to control the main window. Keep returned IDs to control a secondary window from another scene. An ID expires when its window closes. A game can open up to eight secondary windows at a time.

Closing a secondary window unloads its scene if that scene was loaded automatically for the window. An explicitly loaded scene stays in memory and pauses while undisplayed. game.scene.unload(scene) releases the scene and also closes any secondary window displaying it.

Options

Supply only the fields you want to change. Settings last for the play session.

FieldValues
mode"windowed" shows normal decorations, "borderlessWindowed" removes them and keeps the window resizable, and "fullscreen" uses the current display. Fullscreen uses an exclusive mode at the display resolution when supported and falls back to desktop fullscreen otherwise.
aspectRatioA width and height pair such as {16, 9} in Lua or [16, 9] in JavaScript. The ratio must be between 1:32 and 32:1. The game image keeps the requested ratio, with bars where the desktop determines the window size. The runtime also requests matching windowed dimensions. Pass false to clear the override and use the runtime's default layout.
minSize, maxSizeWidth and height in logical pixels, each from 1 to 32768. These limits apply to windowed and borderless windowed modes and must fit with any configured aspect ratio. Pass false to remove a limit.
spanDisplaystrue creates an undecorated window across the bounding rectangle of the connected displays on desktops that allow it. The window fills that rectangle and uses its aspect unless you set aspectRatio. Pass false to return to the selected mode.

This JavaScript callback shows how to preconfigure a scene, span displays, and use the same window controls on a secondary window. Use it as the body of a JavaScript Scene Startup Script.

javascript
let hud;
globalThis.behavior = {
  Start() {
    if (!game.window.isSupported()) return;
    game.scene.setWindowOptions("scene/hud.scene", { aspectRatio: [4, 3] });
    game.window.configure({ spanDisplays: true, aspectRatio: false });
    hud = game.scene.openInWindow("scene/hud.scene");
    game.window.minimize(hud);
  }
};
// In a later callback, call game.window.restore(hud) or game.window.close(hud).

Lua, Luau and JavaScript use the examples' dot syntax. Python takes a dictionary. C# takes an anonymous object or dictionary. Java takes a map and uses 0L for the main window. PHP uses $game->window and associative arrays. C++ uses a RusticValue::Object with RusticValue::Array for pairs. C uses Game.window, takes a JSON object string for options and accepts RUSTIC_CURRENT_WINDOW for the implicit target. For example, inside a generated C callback:

c
if (Game.window.isSupported()) {
    Game.window.configure("{\"mode\":\"windowed\",\"aspectRatio\":[16,9]}", RUSTIC_CURRENT_WINDOW);
    int64_t hud = Game.scene.openInWindow("scene/hud.scene", "{\"maxSize\":[800,600]}");
    Game.window.minimize(hud);
}

Diagnose window behavior

  • If isSupported() returns false, launch native play or test a desktop package.
  • If a scene cannot open, check that it is saved in the snapshot and that the name resolves uniquely. A project-relative file path can disambiguate names.
  • If a window cannot span or enter exclusive fullscreen, check the runtime console for runtime.window warnings. Spanning requires at least two displays and a window manager that accepts window positioning. Displays with different arrangements may leave gaps in the bounding rectangle.
  • Window operations are applied at the runtime boundary after the script callback. A returned ID targets the pending window immediately, but the OS can still reject creation or a mode change. The runtime reports these failures in its console.