On this page
window
Functions and constants to access the window, window event listeners and screen dimming.
Functions
window.set_listener(callback: function(self, event, data) | nil)window.set_mouse_lock(flag: boolean)window.set_dim_mode(mode: Opaque<"constant">)window.get_dim_mode(): Opaque<"constant">window.get_size(): number, numberwindow.get_safe_area(): Record<string | number, unknown>window.get_mouse_lock(): booleanwindow.get_display_scale(): numberwindow.set_title(title: string)window.set_size(width: number, height: number)window.set_position(x: number, y: number)
window.set_listener(callback: function(self, event, data) | nil)
Sets a window event listener. Only one window event listener can be set at a time.
function window_callback(self, event, data) {
if (event === window.WINDOW_EVENT_FOCUS_LOST) {
print("window.WINDOW_EVENT_FOCUS_LOST");
} else if (event === window.WINDOW_EVENT_FOCUS_GAINED) {
print("window.WINDOW_EVENT_FOCUS_GAINED");
} else if (event === window.WINDOW_EVENT_ICONFIED) {
print("window.WINDOW_EVENT_ICONFIED");
} else if (event === window.WINDOW_EVENT_DEICONIFIED) {
print("window.WINDOW_EVENT_DEICONIFIED");
} else if (event === window.WINDOW_EVENT_RESIZED) {
print("Window resized: ", data.width, data.height);
}
}
export default defineScript({
init() {
window.set_listener(window_callback);
},
});
Parameters
callback:function(self, event, data) | nil— A callback which receives info about window events. Pass an empty function ornilif you no longer wish to receive callbacks.
self
object The calling script
event
constant The type of event. Can be one of these:
-
window.WINDOW_EVENT_FOCUS_LOST -
window.WINDOW_EVENT_FOCUS_GAINED -
window.WINDOW_EVENT_RESIZED -
window.WINDOW_EVENT_ICONIFIED -
window.WINDOW_EVENT_DEICONIFIED
data
table The callback value data is a table which currently holds these values
-
number
width: The width of a resize event. nil otherwise. -
number
height: The height of a resize event. nil otherwise.
window.set_mouse_lock(flag: boolean)
Set the locking state for current mouse cursor on a PC platform. This function locks or unlocks the mouse cursor to the center point of the window. While the cursor is locked, mouse position updates will still be sent to the scripts as usual.
Parameters
flag:boolean— The lock state for the mouse cursor
window.set_dim_mode(mode: Opaque<"constant">)
Sets the dimming mode on a mobile device. The dimming mode specifies whether or not a mobile device should dim the screen after a period without user interaction. The dimming mode will only affect the mobile device while the game is in focus on the device, but not when the game is running in the background. This function has no effect on platforms that does not support dimming.
Parameters
-
mode:Opaque<"constant">— The mode for screen dimming -
window.DIMMING_ON -
window.DIMMING_OFF
window.get_dim_mode(): Opaque<"constant">
Returns the current dimming mode set on a mobile device.
The dimming mode specifies whether or not a mobile device should dim the screen after a period without user interaction.
On platforms that does not support dimming, window.DIMMING_UNKNOWN is always returned.
Returns
-
mode:Opaque<"constant">— The mode for screen dimming -
window.DIMMING_UNKNOWN -
window.DIMMING_ON -
window.DIMMING_OFF
window.get_size(): number, number
This returns the current window size (width and height).
Returns
width:number— The window widthheight:number— The window height
window.get_safe_area(): Record<string | number, unknown>
This returns the safe area rectangle (x, y, width, height) and the inset values relative to the window edges. On platforms without a safe area, this returns the full window size and zero insets.
Returns
safe_area:Record<string | number, unknown>— safe area data
safe_area
table table containing these keys:
-
number
x -
number
y -
number
width -
number
height -
number
inset_left -
number
inset_top -
number
inset_right -
number
inset_bottom
window.get_mouse_lock(): boolean
This returns the current lock state of the mouse cursor
Returns
state:boolean— The lock state
window.get_display_scale(): number
This returns the content scale of the current display.
Returns
scale:number— The display scale
window.set_title(title: string)
Sets the window title. Works on desktop platforms.
Parameters
title:string— The title, encoded as UTF-8
window.set_size(width: number, height: number)
Sets the window size. Works on desktop platforms only.
Parameters
width:number— Width of windowheight:number— Height of window
window.set_position(x: number, y: number)
Sets the window position.
Parameters
x:number— Horizontal position of windowy:number— Vertical position of window
Constants
window.WINDOW_EVENT_FOCUS_LOST
This event is sent to a window event listener when the game window or app screen has lost focus.
window.WINDOW_EVENT_FOCUS_GAINED
This event is sent to a window event listener when the game window or app screen has gained focus. This event is also sent at game startup and the engine gives focus to the game.
window.WINDOW_EVENT_RESIZED
This event is sent to a window event listener when the game window or app screen is resized. The new size is passed along in the data field to the event listener.
window.WINDOW_EVENT_ICONFIED
This event is sent to a window event listener when the game window or app screen is iconified (reduced to an application icon in a toolbar, application tray or similar).
window.WINDOW_EVENT_DEICONIFIED
This event is sent to a window event listener when the game window or app screen is restored after being iconified.
window.DIMMING_ON
Dimming mode is used to control whether or not a mobile device should dim the screen after a period without user interaction.
window.DIMMING_OFF
Dimming mode is used to control whether or not a mobile device should dim the screen after a period without user interaction.
window.DIMMING_UNKNOWN
Dimming mode is used to control whether or not a mobile device should dim the screen after a period without user interaction. This mode indicates that the dim mode can't be determined, or that the platform doesn't support dimming.