MainLoop

Abstract base class for the game's main loop.

MainLoop is the abstract base class for a Godot project's game loop. It is inherited by SceneTree, which is the default game loop implementation used in Godot projects, though it is also possible to write and use one's own MainLoop subclass instead of the scene tree. Upon the application start, a MainLoop implementation must be provided to the OS; otherwise, the application will exit. This happens automatically (and a SceneTree is created) unless a main Script is provided from the command line (with e.g. godot -s my_loop.gd, which should then be a MainLoop implementation. Here is an example script implementing a simple MainLoop:

More...

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

Constants
enum Constants

Functions

_dropFiles
void _dropFiles(PoolStringArray files, long from_screen)

Called when files are dragged from the OS file manager and dropped in the game window. The arguments are a list of file paths and the identifier of the screen where the drag originated.

_finalize
void _finalize()

Called before the program exits.

_globalMenuAction
void _globalMenuAction(VariantArg0 id, VariantArg1 meta)

Called when the user performs an action in the system global menu (e.g. the Mac OS menu bar).

_idle
bool _idle(double delta)

Called each idle frame with the time since the last idle frame as argument (in seconds). Equivalent to Node._process. If implemented, the method must return a boolean value. true ends the main loop, while false lets it proceed to the next frame.

_init
void _init()

Should not be called manually, override _initialize instead. Will be removed in Godot 4.0.

_initialize
void _initialize()

Called once during initialization.

_inputEvent
void _inputEvent(InputEvent event)

Called whenever an InputEvent is received by the main loop.

_inputText
void _inputText(String text)

Deprecated callback, does not do anything. Use _inputEvent to parse text input. Will be removed in Godot 4.0.

_iteration
bool _iteration(double delta)

Called each physics frame with the time since the last physics frame as argument (delta, in seconds). Equivalent to Node._physicsProcess. If implemented, the method must return a boolean value. true ends the main loop, while false lets it proceed to the next frame.

finish
void finish()

Should not be called manually, override _finalize instead. Will be removed in Godot 4.0.

idle
bool idle(double delta)

Should not be called manually, override _idle instead. Will be removed in Godot 4.0.

inputEvent
void inputEvent(InputEvent event)

Should not be called manually, override _inputEvent instead. Will be removed in Godot 4.0.

inputText
void inputText(String text)

Should not be called manually, override _inputText instead. Will be removed in Godot 4.0.

iteration
bool iteration(double delta)

Should not be called manually, override _iteration instead. Will be removed in Godot 4.0.

opAssign
typeof(null) opAssign(typeof(null) n)
opEquals
bool opEquals(MainLoop other)
opEquals
bool opEquals(typeof(null) n)
toHash
size_t toHash()

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Static functions

_new
MainLoop _new()

Construct a new instance of MainLoop. Note: use memnew!MainLoop instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Detailed Description

extends MainLoop

var time_elapsed = 0 var keys_typed = [] var quit = false

func _initialize(): print("Initialized:") print(" Starting time: %s" % str(time_elapsed))

func _idle(delta): time_elapsed += delta # Return true to end the main loop. return quit

func _input_event(event): # Record keys. if event is InputEventKey and event.pressed and !event.echo: keys_typed.append(OS.get_scancode_string(event.scancode)) # Quit on Escape press. if event.scancode == KEY_ESCAPE: quit = true # Quit on any mouse click. if event is InputEventMouseButton: quit = true

func _finalize(): print("Finalized:") print(" End time: %s" % str(time_elapsed)) print(" Keys typed: %s" % var2str(keys_typed))

Meta