- Select ref document -

Window API documentation

version 1.2.159

Functions and constants to access the window, window event listeners and screen dimming.

Functions

window.get_dim_mode

window.get_dim_mode()

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

constant The mode for screen dimming

  • window.DIMMING_UNKNOWN
  • window.DIMMING_ON
  • window.DIMMING_OFF
mode

constant The mode for screen dimming

  • window.DIMMING_UNKNOWN
  • window.DIMMING_ON
  • window.DIMMING_OFF

window.set_dim_mode

window.set_dim_mode(mode)

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

constant The mode for screen dimming

  • window.DIMMING_ON
  • window.DIMMING_OFF
mode

constant The mode for screen dimming

  • window.DIMMING_ON
  • window.DIMMING_OFF

window.set_listener

window.set_listener(callback)

Sets a window event listener.

Parameters

callback

function(self, event, data) A callback which receives info about window events. Pass an empty function if 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
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.
callback

function(self, event, data) A callback which receives info about window events. Pass an empty function if 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
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.

Examples

function window_callback(self, event, data)
    if event == window.WINDOW_EVENT_FOCUS_LOST then
        print("window.WINDOW_EVENT_FOCUS_LOST")
    elseif event == window.WINDOW_EVENT_FOCUS_GAINED then
        print("window.WINDOW_EVENT_FOCUS_GAINED")
    elseif event == window.WINDOW_EVENT_RESIZED then
        print("Window resized: ", data.width, data.height)
    end
end

function init(self)
    window.set_listener(window_callback)
end

Constants

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_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_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.

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_FOCUS_LOST

This event is sent to a window event listener when the game window or app screen has lost focus.

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.