Skip to content

Lua API: 2. Window

MCUmbrella edited this page Nov 24, 2023 · 1 revision

Window

Static functions

getX, getY

Get the coordinates of the top-left corner of the window relative to the top-left corner of the screen.

Return: Integer starting from 0. X is larger the further to the right, Y is larger the further to the bottom.

setLocation

Set the location mentioned above.

Parameter:

  • Number x
  • Number y

Example:

-- Put this into tick() to see the window move down to the right
Window.setLocation(
  Window.getX() + 1,
  Window.getY() + 1
)

getWidth, getHeight

Get the size of the window.

Return: Non-negative integer

setSize

Set the size of the window.

Parameter:

  • Number width
  • Number height

Example:

-- Swap the width and height of the window
Window.setSize(Window.getHeight(), Window.getWidth())

getTitle

Get the title of the window.

Return: String

setTitle

Set the title of the window.

Parameter:

  • String title: The new title to be set.

Example:

-- Put this into tick() to display the current tick in the window title
Window.setTitle("Tick #" .. Engine.currentTick())

fullscreen

Check or control the window's fullscreen state.

Parameter:

  • Boolean state (optional): Whether to turn on fullscreen. If the parameter is not present, the fullscreen state remains unchanged.

Return: The current fullscreen state.

Example:

-- Press F11 to toggle fullscreen
if Keyboard.pressed(68) -- F11
then
  Window.fullscreen(not Window.fullscreen())
end

resizable

Check or control the window's resizable state.

Parameter:

  • Boolean state (optional): Whether to make the window resizable. If the parameter is not present, the resizable state remains unchanged.

Return: The current resizable state.

Example:

Window.resizable(true) -- allows window resizing