class GameState : Object
__new(self: Object, ...: any)

The default constructor for the class. Subclasses should override this.

manager: GameStateManager?

The state’s manager or nil if the state is not in a manager’s stack.

load(self: GameState, previous?: GameState, ...: any)

Called when this state is pushed or switched to.

unload(self: GameState, next: GameState, ...: any)

Called when the manager switches away from or pops this state off.

resume(self: GameState, previous?: GameState, ...: any)

Called when a state is popped and this one becomes active.

pause(self: GameState, next: GameState, ...: any)

Called when a state is pushed on top of this one.

getManager(self: GameState) GameStateManager
audiodisconnected(self: GameState, sources: (love.audio.Source)[]) reconnected: boolean

Called when the active audio device is disconnected (e.g. physically unplugging headphones). All audio are stopped and loses their playback position when this callback is called.

[Open in Browser](https://love2d.org/wiki/love.audiodisconnected)

Parameters:

sources ((love.audio.Source)[]) – List of sources that was playing.

Returns:

reconnected (boolean) – Is audio re-connection attempt has been done?

directorydropped(self: GameState, path: string, x: number, y: number)

Callback function triggered when a directory is dragged and dropped onto the window.

Paths passed into this callback are able to be used with love.filesystem.mount, which is the only way to get read access via love.filesystem to the dropped directory. love.filesystem.mount does not generally accept other full platform-dependent directory paths that haven’t been dragged and dropped onto the window.

[Open in Browser](https://love2d.org/wiki/love.directorydropped)

Parameters:

path (string) – The full platform-dependent path to the directory. It can be used as an argument to love.filesystem.mount, in order to gain read access to the directory with love.filesystem.

displayrotated(self: GameState, index: number, orientation: "landscape" | "landscapeflipped" | "portrait" | "portraitflipped" | "unknown")

Called when the device display orientation changed, for example, user rotated their phone 180 degrees.

[Open in Browser](https://love2d.org/wiki/love.displayrotated)

Parameters:
  • index (number) – The index of the display that changed orientation.

  • orientation ("landscape" | "landscapeflipped" | "portrait" | "portraitflipped" | "unknown") – The new orientation.

draw(self: GameState)

Callback function used to draw on the screen every frame.

[Open in Browser](https://love2d.org/wiki/love.draw)

dropbegan(self: GameState)

[Open in Browser](https://love2d.org/wiki/love.dropbegan)

dropcompleted(self: GameState, x: number, y: number)

[Open in Browser](https://love2d.org/wiki/love.dropcompleted)

dropmoved(self: GameState, x: number, y: number)

[Open in Browser](https://love2d.org/wiki/love.dropmoved)

errorhandler(self: GameState, msg: string) mainLoop: fun(): any

The error handler, used to display error messages.

[Open in Browser](https://love2d.org/wiki/love.errorhandler)

Parameters:

msg (string) – The error message.

Returns:

mainLoop (fun(): any) – Function which handles one frame, including events and rendering, when called. If this is nil then LÖVE exits immediately.

exposesd(self: GameState)

[Open in Browser](https://love2d.org/wiki/love.exposesd)

filedropped(self: GameState, file: love.filesystem.File, x: number, y: number)

Callback function triggered when a file is dragged and dropped onto the window.

[Open in Browser](https://love2d.org/wiki/love.filedropped)

Parameters:

file (love.filesystem.File) – The unopened File object representing the file that was dropped.

focus(self: GameState, self: any, focus: boolean)

Callback function triggered when window receives or loses focus.

[Open in Browser](https://love2d.org/wiki/love.focus)

Parameters:

focus (boolean) – True if the window gains focus, false if it loses focus.

gamepadaxis(self: GameState, joystick: love.joystick.Joystick, axis: "leftx" | "lefty" | "rightx" | "righty" | "triggerleft"...(+1), value: number)

Called when a Joystick’s virtual gamepad axis is moved.

[Open in Browser](https://love2d.org/wiki/love.gamepadaxis)

Parameters:
  • joystick (love.joystick.Joystick) – The joystick object.

  • axis ("leftx" | "lefty" | "rightx" | "righty" | "triggerleft"...(+1)) – The virtual gamepad axis.

  • value (number) – The new axis value.

gamepadpressed(self: GameState, joystick: love.joystick.Joystick, button: "a" | "b" | "back" | "dpdown" | "dpleft"...(+16))

Called when a Joystick’s virtual gamepad button is pressed.

[Open in Browser](https://love2d.org/wiki/love.gamepadpressed)

Parameters:
  • joystick (love.joystick.Joystick) – The joystick object.

  • button ("a" | "b" | "back" | "dpdown" | "dpleft"...(+16)) – The virtual gamepad button.

gamepadreleased(self: GameState, joystick: love.joystick.Joystick, button: "a" | "b" | "back" | "dpdown" | "dpleft"...(+16))

Called when a Joystick’s virtual gamepad button is released.

[Open in Browser](https://love2d.org/wiki/love.gamepadreleased)

Parameters:
  • joystick (love.joystick.Joystick) – The joystick object.

  • button ("a" | "b" | "back" | "dpdown" | "dpleft"...(+16)) – The virtual gamepad button.

joystickadded(self: GameState, joystick: love.joystick.Joystick)

Called when a Joystick is connected.

This callback is also triggered after love.load for every Joystick which was already connected when the game started up.

[Open in Browser](https://love2d.org/wiki/love.joystickadded)

Parameters:

joystick (love.joystick.Joystick) – The newly connected Joystick object.

joystickaxis(self: GameState, joystick: love.joystick.Joystick, axis: number, value: number)

Called when a joystick axis moves.

[Open in Browser](https://love2d.org/wiki/love.joystickaxis)

Parameters:
  • joystick (love.joystick.Joystick) – The joystick object.

  • axis (number) – The axis number.

  • value (number) – The new axis value.

joystickhat(self: GameState, joystick: love.joystick.Joystick, hat: number, direction: "c" | "d" | "l" | "ld" | "lu"...(+4))

Called when a joystick hat direction changes.

[Open in Browser](https://love2d.org/wiki/love.joystickhat)

Parameters:
  • joystick (love.joystick.Joystick) – The joystick object.

  • hat (number) – The hat number.

  • direction ("c" | "d" | "l" | "ld" | "lu"...(+4)) – The new hat direction.

joystickpressed(self: GameState, joystick: love.joystick.Joystick, button: number)

Called when a joystick button is pressed.

[Open in Browser](https://love2d.org/wiki/love.joystickpressed)

Parameters:
  • joystick (love.joystick.Joystick) – The joystick object.

  • button (number) – The button number.

joystickreleased(self: GameState, joystick: love.joystick.Joystick, button: number)

Called when a joystick button is released.

[Open in Browser](https://love2d.org/wiki/love.joystickreleased)

Parameters:
  • joystick (love.joystick.Joystick) – The joystick object.

  • button (number) – The button number.

joystickremoved(self: GameState, joystick: love.joystick.Joystick)

Called when a Joystick is disconnected.

[Open in Browser](https://love2d.org/wiki/love.joystickremoved)

Parameters:

joystick (love.joystick.Joystick) – The now-disconnected Joystick object.

joysticksensorupdated(self: GameState, joystick: love.joystick.Joystick, sensorType: "accelerometer" | "gyroscope", x: number, y: number, z: number)

Called when a Joystick’s sensor is updated with new values. Only Joystick sensors enabled with Joystick:setSensorEnabled will trigger this event.

[Open in Browser](https://love2d.org/wiki/love.joysticksensorupdated)

Parameters:
  • joystick (love.joystick.Joystick) – The joystick object.

  • sensorType ("accelerometer" | "gyroscope") – The type of sensor.

  • x (number) – The new sensor 1st value.

  • y (number) – The new sensor 2nd value.

  • z (number) – The new sensor 3rd value.

keypressed(self: GameState, key: "!" | "" | "#" | "$" | "&"...(+139), scancode: "'" | "," | "-" | "." | "/"...(+189), isrepeat: boolean)

Callback function triggered when a key is pressed.

Scancodes are keyboard layout-independent, so the scancode ‘w’ will be generated if the key in the same place as the ‘w’ key on an American keyboard is pressed, no matter what the key is labelled or what the user’s operating system settings are.

Key repeat needs to be enabled with love.keyboard.setKeyRepeat for repeat keypress events to be received. This does not affect love.textinput.

[Open in Browser](https://love2d.org/wiki/love.keypressed)

Parameters:
  • key ("!" | "" | "#" | "$" | "&"...(+139)) – Character of the pressed key.

  • scancode ("'" | "," | "-" | "." | "/"...(+189)) – The scancode representing the pressed key.

  • isrepeat (boolean) – Whether this keypress event is a repeat. The delay between key repeats depends on the user’s system settings.

keyreleased(self: GameState, key: "!" | "" | "#" | "$" | "&"...(+139), scancode: "'" | "," | "-" | "." | "/"...(+189))

Callback function triggered when a keyboard key is released.

Scancodes are keyboard layout-independent, so the scancode ‘w’ will be used if the key in the same place as the ‘w’ key on an American keyboard is pressed, no matter what the key is labelled or what the user’s operating system settings are.

[Open in Browser](https://love2d.org/wiki/love.keyreleased)

Parameters:
  • key ("!" | "" | "#" | "$" | "&"...(+139)) – Character of the released key.

  • scancode ("'" | "," | "-" | "." | "/"...(+189)) – The scancode representing the released key.

localechanged(self: GameState)

Callback function triggered when the user’s system locale preferences have changed.

[Open in Browser](https://love2d.org/wiki/love.localechanged)

lowmemory(self: GameState)

Callback function triggered when the system is running out of memory on mobile devices.

Mobile operating systems may forcefully kill the game if it uses too much memory, so any non-critical resource should be removed if possible (by setting all variables referencing the resources to ‘’’nil’’’), when this event is triggered. Sounds and images in particular tend to use the most memory.

[Open in Browser](https://love2d.org/wiki/love.lowmemory)

mousefocus(self: GameState, focus: boolean)

Callback function triggered when window receives or loses mouse focus.

[Open in Browser](https://love2d.org/wiki/love.mousefocus)

Parameters:

focus (boolean) – Whether the window has mouse focus or not.

mousemoved(self: GameState, x: number, y: number, dx: number, dy: number, istouch: boolean)

Callback function triggered when the mouse is moved.

If Relative Mode is enabled for the mouse, the ‘’’dx’’’ and ‘’’dy’’’ arguments of this callback will update but ‘’’x’’’ and ‘’’y’’’ are not guaranteed to.

[Open in Browser](https://love2d.org/wiki/love.mousemoved)

Parameters:
  • x (number) – The mouse position on the x-axis.

  • y (number) – The mouse position on the y-axis.

  • dx (number) – The amount moved along the x-axis since the last time love.mousemoved was called.

  • dy (number) – The amount moved along the y-axis since the last time love.mousemoved was called.

  • istouch (boolean) – True if the mouse button press originated from a touchscreen touch-press.

mousepressed(self: GameState, x: number, y: number, button: number, istouch: boolean, presses: number)

Callback function triggered when a mouse button is pressed.

Use love.wheelmoved to detect mouse wheel motion. It will not register as a button press in version 0.10.0 and newer.

[Open in Browser](https://love2d.org/wiki/love.mousepressed)

Parameters:
  • x (number) – Mouse x position, in pixels.

  • y (number) – Mouse y position, in pixels.

  • button (number) – The button index that was pressed. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependent.

  • istouch (boolean) – True if the mouse button press originated from a touchscreen touch-press.

  • presses (number) – The number of presses in a short time frame and small area, used to simulate double, triple clicks

mousereleased(self: GameState, x: number, y: number, button: number, istouch: boolean, presses: number)

Callback function triggered when a mouse button is released.

[Open in Browser](https://love2d.org/wiki/love.mousereleased)

Parameters:
  • x (number) – Mouse x position, in pixels.

  • y (number) – Mouse y position, in pixels.

  • button (number) – The button index that was released. 1 is the primary mouse button, 2 is the secondary mouse button and 3 is the middle button. Further buttons are mouse dependent.

  • istouch (boolean) – True if the mouse button release originated from a touchscreen touch-release.

  • presses (number) – The number of presses in a short time frame and small area, used to simulate double, triple clicks

occluded(self: GameState)

[Open in Browser](https://love2d.org/wiki/love.occluded)

quit(self: GameState) r: boolean

Callback function triggered when the game is closed.

[Open in Browser](https://love2d.org/wiki/love.quit)

Returns:

r (boolean) – Abort quitting. If true, do not close the game.

resize(self: GameState, w: number, h: number)

Called when the window is resized, for example if the user resizes the window, or if love.window.setMode is called with an unsupported width or height in fullscreen and the window chooses the closest appropriate size.

Calls to love.window.setMode will ‘’’only’’’ trigger this event if the width or height of the window after the call doesn’t match the requested width and height. This can happen if a fullscreen mode is requested which doesn’t match any supported mode, or if the fullscreen type is ‘desktop’ and the requested width or height don’t match the desktop resolution.

Since 11.0, this function returns width and height in DPI-scaled units rather than pixels.

[Open in Browser](https://love2d.org/wiki/love.resize)

Parameters:
  • w (number) – The new width.

  • h (number) – The new height.

run(self: GameState) mainLoop: fun(): any

The main function, containing the main loop. A sensible default is used when left out.

[Open in Browser](https://love2d.org/wiki/love.run)

Returns:

mainLoop (fun(): any) – Function which handlers one frame, including events and rendering when called.

sensorupdated(self: GameState, sensorType: "accelerometer" | "gyroscope", x: number, y: number, z: number)

Called when the in-device sensor is updated with new values. Only sensors enabled with love.sensor.setEnabled will trigger this event.

[Open in Browser](https://love2d.org/wiki/love.sensorupdated)

Parameters:
  • sensorType ("accelerometer" | "gyroscope") – The type of sensor.

  • x (number) – The new sensor 1st value.

  • y (number) – The new sensor 2nd value.

  • z (number) – The new sensor 3rd value.

textedited(self: GameState, text: string, start: number, length: number)

Called when the candidate text for an IME (Input Method Editor) has changed.

The candidate text is not the final text that the user will eventually choose. Use love.textinput for that.

[Open in Browser](https://love2d.org/wiki/love.textedited)

Parameters:
  • text (string) – The UTF-8 encoded unicode candidate text.

  • start (number) – The start cursor of the selected candidate text.

  • length (number) – The length of the selected candidate text. May be 0.

textinput(self: GameState, text: string)

Called when text has been entered by the user. For example if shift-2 is pressed on an American keyboard layout, the text ‘@’ will be generated.

Although Lua strings can store UTF-8 encoded unicode text just fine, many functions in Lua’s string library will not treat the text as you might expect. For example, #text (and string.len(text)) will give the number of ‘’bytes’’ in the string, rather than the number of unicode characters. The Lua wiki and a presentation by one of Lua’s creators give more in-depth explanations, with some tips.

The utf8 library can be used to operate on UTF-8 encoded unicode text (such as the text argument given in this function.)

On Android and iOS, textinput is disabled by default; call love.keyboard.setTextInput to enable it.

[Open in Browser](https://love2d.org/wiki/love.textinput)

Parameters:

text (string) – The UTF-8 encoded unicode text.

threaderror(self: GameState, thread: love.thread.Thread, errorstr: string)

Callback function triggered when a Thread encounters an error.

[Open in Browser](https://love2d.org/wiki/love.threaderror)

Parameters:
  • thread (love.thread.Thread) – The thread which produced the error.

  • errorstr (string) – The error message.

touchmoved(self: GameState, id: lightuserdata, x: number, y: number, dx: number, dy: number, pressure: number)

Callback function triggered when a touch press moves inside the touch screen.

The identifier is only guaranteed to be unique for the specific touch press until love.touchreleased is called with that identifier, at which point it may be reused for new touch presses.

The unofficial Android and iOS ports of LÖVE 0.9.2 reported touch positions as normalized values in the range of 1, whereas this API reports positions in pixels.

[Open in Browser](https://love2d.org/wiki/love.touchmoved)

Parameters:
  • id (lightuserdata) – The identifier for the touch press.

  • x (number) – The x-axis position of the touch inside the window, in pixels.

  • y (number) – The y-axis position of the touch inside the window, in pixels.

  • dx (number) – The x-axis movement of the touch inside the window, in pixels.

  • dy (number) – The y-axis movement of the touch inside the window, in pixels.

  • pressure (number) – The amount of pressure being applied. Most touch screens aren’t pressure sensitive, in which case the pressure will be 1.

touchpressed(self: GameState, id: lightuserdata, x: number, y: number, dx: number, dy: number, pressure: number)

Callback function triggered when the touch screen is touched.

The identifier is only guaranteed to be unique for the specific touch press until love.touchreleased is called with that identifier, at which point it may be reused for new touch presses.

The unofficial Android and iOS ports of LÖVE 0.9.2 reported touch positions as normalized values in the range of 1, whereas this API reports positions in pixels.

[Open in Browser](https://love2d.org/wiki/love.touchpressed)

Parameters:
  • id (lightuserdata) – The identifier for the touch press.

  • x (number) – The x-axis position of the touch press inside the window, in pixels.

  • y (number) – The y-axis position of the touch press inside the window, in pixels.

  • dx (number) – The x-axis movement of the touch press inside the window, in pixels. This should always be zero.

  • dy (number) – The y-axis movement of the touch press inside the window, in pixels. This should always be zero.

  • pressure (number) – The amount of pressure being applied. Most touch screens aren’t pressure sensitive, in which case the pressure will be 1.

touchreleased(self: GameState, id: lightuserdata, x: number, y: number, dx: number, dy: number, pressure: number)

Callback function triggered when the touch screen stops being touched.

The identifier is only guaranteed to be unique for the specific touch press until love.touchreleased is called with that identifier, at which point it may be reused for new touch presses.

The unofficial Android and iOS ports of LÖVE 0.9.2 reported touch positions as normalized values in the range of 1, whereas this API reports positions in pixels.

[Open in Browser](https://love2d.org/wiki/love.touchreleased)

Parameters:
  • id (lightuserdata) – The identifier for the touch press.

  • x (number) – The x-axis position of the touch inside the window, in pixels.

  • y (number) – The y-axis position of the touch inside the window, in pixels.

  • dx (number) – The x-axis movement of the touch inside the window, in pixels.

  • dy (number) – The y-axis movement of the touch inside the window, in pixels.

  • pressure (number) – The amount of pressure being applied. Most touch screens aren’t pressure sensitive, in which case the pressure will be 1.

update(self: GameState, dt: number)

Callback function used to update the state of the game every frame.

[Open in Browser](https://love2d.org/wiki/love.update)

Parameters:

dt (number) – Time since the last update in seconds.

visible(self: GameState, visible: boolean)

Callback function triggered when window is minimized/hidden or unminimized by the user.

[Open in Browser](https://love2d.org/wiki/love.visible)

Parameters:

visible (boolean) – True if the window is visible, false if it isn’t.

wheelmoved(self: GameState, x: number, y: number, dir: string)

Callback function triggered when the mouse wheel is moved.

[Open in Browser](https://love2d.org/wiki/love.wheelmoved)

Parameters:
  • x (number) – Amount of horizontal mouse wheel movement. Positive values indicate movement to the right.

  • y (number) – Amount of vertical mouse wheel movement. Positive values indicate upward movement.

  • dir (string) – flipped