2017-09-12 20:42:36 +00:00
<?xml version="1.0" encoding="UTF-8" ?>
2020-02-01 01:03:48 +00:00
<class name= "MainLoop" inherits= "Object" version= "4.0" >
2017-09-12 20:42:36 +00:00
<brief_description >
2019-06-26 13:57:13 +00:00
Abstract base class for the game's main loop.
2017-09-12 20:42:36 +00:00
</brief_description>
<description >
2019-08-19 17:40:31 +00:00
[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.
2019-06-21 23:04:47 +00:00
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. [code]godot -s my_loop.gd[/code], which should then be a [MainLoop] implementation.
2019-06-26 13:57:13 +00:00
Here is an example script implementing a simple [MainLoop]:
2020-03-31 09:56:58 +00:00
[b]FIXME:[/b] No longer valid after DisplayServer split and Input refactoring.
2019-06-26 13:57:13 +00:00
[codeblock]
extends MainLoop
var time_elapsed = 0
var keys_typed = []
var quit = false
func _initialize():
2019-10-01 08:55:49 +00:00
print("Initialized:")
print(" Starting time: %s" % str(time_elapsed))
2019-06-26 13:57:13 +00:00
func _idle(delta):
2019-10-01 08:55:49 +00:00
time_elapsed += delta
# Return true to end the main loop.
return quit
2019-06-26 13:57:13 +00:00
func _input_event(event):
2019-10-01 08:55:49 +00:00
# Record keys.
if event is InputEventKey and event.pressed and !event.echo:
2018-04-05 17:59:35 +00:00
keys_typed.append(OS.get_keycode_string(event.keycode))
2019-10-01 08:55:49 +00:00
# Quit on Escape press.
2018-04-05 17:59:35 +00:00
if event.keycode == KEY_ESCAPE:
2019-10-01 08:55:49 +00:00
quit = true
# Quit on any mouse click.
if event is InputEventMouseButton:
quit = true
2019-06-26 13:57:13 +00:00
func _finalize():
2019-10-01 08:55:49 +00:00
print("Finalized:")
print(" End time: %s" % str(time_elapsed))
print(" Keys typed: %s" % var2str(keys_typed))
2019-06-26 13:57:13 +00:00
[/codeblock]
2017-09-12 20:42:36 +00:00
</description>
<tutorials >
</tutorials>
<methods >
<method name= "_finalize" qualifiers= "virtual" >
<return type= "void" >
</return>
<description >
Called before the program exits.
</description>
</method>
<method name= "_idle" qualifiers= "virtual" >
2019-06-26 13:57:13 +00:00
<return type= "bool" >
2017-09-12 20:42:36 +00:00
</return>
<argument index= "0" name= "delta" type= "float" >
</argument>
<description >
2019-06-26 13:57:13 +00:00
Called each idle frame with the time since the last idle frame as argument (in seconds). Equivalent to [method Node._process].
If implemented, the method must return a boolean value. [code]true[/code] ends the main loop, while [code]false[/code] lets it proceed to the next frame.
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "_initialize" qualifiers= "virtual" >
<return type= "void" >
</return>
<description >
Called once during initialization.
</description>
</method>
<method name= "_iteration" qualifiers= "virtual" >
2019-06-26 13:57:13 +00:00
<return type= "bool" >
2017-09-12 20:42:36 +00:00
</return>
<argument index= "0" name= "delta" type= "float" >
</argument>
<description >
2019-06-26 13:57:13 +00:00
Called each physics frame with the time since the last physics frame as argument (in seconds). Equivalent to [method Node._physics_process].
If implemented, the method must return a boolean value. [code]true[/code] ends the main loop, while [code]false[/code] lets it proceed to the next frame.
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "finish" >
<return type= "void" >
</return>
<description >
2019-06-26 13:57:13 +00:00
Should not be called manually, override [method _finalize] instead. Will be removed in Godot 4.0.
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "idle" >
<return type= "bool" >
</return>
<argument index= "0" name= "delta" type= "float" >
</argument>
<description >
2019-06-26 13:57:13 +00:00
Should not be called manually, override [method _idle] instead. Will be removed in Godot 4.0.
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "init" >
<return type= "void" >
</return>
<description >
2019-06-26 13:57:13 +00:00
Should not be called manually, override [method _initialize] instead. Will be removed in Godot 4.0.
2017-09-12 20:42:36 +00:00
</description>
</method>
<method name= "iteration" >
<return type= "bool" >
</return>
<argument index= "0" name= "delta" type= "float" >
</argument>
<description >
2019-06-26 13:57:13 +00:00
Should not be called manually, override [method _iteration] instead. Will be removed in Godot 4.0.
2017-09-12 20:42:36 +00:00
</description>
</method>
</methods>
2019-10-06 18:17:44 +00:00
<signals >
<signal name= "on_request_permissions_result" >
<argument index= "0" name= "permission" type= "String" >
</argument>
<argument index= "1" name= "granted" type= "bool" >
</argument>
<description >
2020-01-10 18:46:41 +00:00
Emitted when a user responds to a permission request.
2019-10-06 18:17:44 +00:00
</description>
</signal>
</signals>
2017-09-12 20:42:36 +00:00
<constants >
2020-03-31 09:56:58 +00:00
<constant name= "NOTIFICATION_OS_MEMORY_WARNING" value= "2009" >
2019-06-26 13:57:13 +00:00
Notification received from the OS when the application is exceeding its allocated memory.
Specific to the iOS platform.
2017-09-12 20:42:36 +00:00
</constant>
2020-03-31 09:56:58 +00:00
<constant name= "NOTIFICATION_TRANSLATION_CHANGED" value= "2010" >
2019-06-26 13:57:13 +00:00
Notification received when translations may have changed. Can be triggered by the user changing the locale. Can be used to respond to language changes, for example to change the UI strings on the fly. Useful when working with the built-in translation support, like [method Object.tr].
2017-09-12 20:42:36 +00:00
</constant>
2020-03-31 09:56:58 +00:00
<constant name= "NOTIFICATION_WM_ABOUT" value= "2011" >
2019-06-26 13:57:13 +00:00
Notification received from the OS when a request for "About" information is sent.
Specific to the macOS platform.
2017-09-12 20:42:36 +00:00
</constant>
2020-03-31 09:56:58 +00:00
<constant name= "NOTIFICATION_CRASH" value= "2012" >
2019-06-26 13:57:13 +00:00
Notification received from Godot's crash handler when the engine is about to crash.
Implemented on desktop platforms if the crash handler is enabled.
2018-07-26 09:56:21 +00:00
</constant>
2020-03-31 09:56:58 +00:00
<constant name= "NOTIFICATION_OS_IME_UPDATE" value= "2013" >
2019-06-26 13:57:13 +00:00
Notification received from the OS when an update of the Input Method Engine occurs (e.g. change of IME cursor position or composition string).
Specific to the macOS platform.
2018-11-23 12:07:48 +00:00
</constant>
2020-07-01 12:18:13 +00:00
<constant name= "NOTIFICATION_APPLICATION_RESUMED" value= "2014" >
Notification received from the OS when the application is resumed.
2019-09-09 21:42:17 +00:00
Specific to the Android platform.
</constant>
2020-07-01 12:18:13 +00:00
<constant name= "NOTIFICATION_APPLICATION_PAUSED" value= "2015" >
Notification received from the OS when the application is paused.
2019-09-09 21:42:17 +00:00
Specific to the Android platform.
</constant>
2020-07-01 12:18:13 +00:00
<constant name= "NOTIFICATION_APPLICATION_FOCUS_IN" value= "2016" >
Notification received from the OS when the application is focused, i.e. when changing the focus from the OS desktop or a thirdparty application to any open window of the Godot instance.
Implemented on desktop platforms.
</constant>
<constant name= "NOTIFICATION_APPLICATION_FOCUS_OUT" value= "2017" >
Notification received from the OS when the application is defocused, i.e. when changing the focus from any open window of the Godot instance to the OS desktop or a thirdparty application.
Implemented on desktop platforms.
</constant>
2017-09-12 20:42:36 +00:00
</constants>
</class>