mirror of
https://github.com/stan220/godot-docs.git
synced 2026-09-08 18:29:11 +00:00
classref: Sync with current master branch (f87858a8f)
This commit is contained in:
+124
-43
@@ -16,14 +16,16 @@ MainLoop
|
||||
|
||||
Abstract base class for the game's main loop.
|
||||
|
||||
.. rst-class:: classref-introduction-group
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
``MainLoop`` is the abstract base class for a Godot project's game loop. It is inherited by :ref:`SceneTree<class_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.
|
||||
**MainLoop** is the abstract base class for a Godot project's game loop. It is inherited by :ref:`SceneTree<class_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 :ref:`SceneTree<class_SceneTree>` is created) unless a ``MainLoop`` :ref:`Script<class_Script>` is provided from the command line (with e.g. ``godot -s my_loop.gd`` or the "Main Loop Type" project setting is overwritten.
|
||||
Upon the application start, a **MainLoop** implementation must be provided to the OS; otherwise, the application will exit. This happens automatically (and a :ref:`SceneTree<class_SceneTree>` is created) unless a **MainLoop** :ref:`Script<class_Script>` is provided from the command line (with e.g. ``godot -s my_loop.gd`` or the "Main Loop Type" project setting is overwritten.
|
||||
|
||||
Here is an example script implementing a simple ``MainLoop``:
|
||||
Here is an example script implementing a simple **MainLoop**:
|
||||
|
||||
|
||||
.. tabs::
|
||||
@@ -79,119 +81,198 @@ Here is an example script implementing a simple ``MainLoop``:
|
||||
|
||||
|
||||
|
||||
.. rst-class:: classref-reftable-group
|
||||
|
||||
Methods
|
||||
-------
|
||||
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
| void | :ref:`_finalize<class_MainLoop_method__finalize>` **(** **)** |virtual| |
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
| void | :ref:`_initialize<class_MainLoop_method__initialize>` **(** **)** |virtual| |
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_physics_process<class_MainLoop_method__physics_process>` **(** :ref:`float<class_float>` delta **)** |virtual| |
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_process<class_MainLoop_method__process>` **(** :ref:`float<class_float>` delta **)** |virtual| |
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
.. table::
|
||||
:widths: auto
|
||||
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
| void | :ref:`_finalize<class_MainLoop_method__finalize>` **(** **)** |virtual| |
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
| void | :ref:`_initialize<class_MainLoop_method__initialize>` **(** **)** |virtual| |
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_physics_process<class_MainLoop_method__physics_process>` **(** :ref:`float<class_float>` delta **)** |virtual| |
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
| :ref:`bool<class_bool>` | :ref:`_process<class_MainLoop_method__process>` **(** :ref:`float<class_float>` delta **)** |virtual| |
|
||||
+-------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
.. rst-class:: classref-section-separator
|
||||
|
||||
----
|
||||
|
||||
.. rst-class:: classref-descriptions-group
|
||||
|
||||
Signals
|
||||
-------
|
||||
|
||||
.. _class_MainLoop_signal_on_request_permissions_result:
|
||||
|
||||
- **on_request_permissions_result** **(** :ref:`String<class_String>` permission, :ref:`bool<class_bool>` granted **)**
|
||||
.. rst-class:: classref-signal
|
||||
|
||||
**on_request_permissions_result** **(** :ref:`String<class_String>` permission, :ref:`bool<class_bool>` granted **)**
|
||||
|
||||
Emitted when a user responds to a permission request.
|
||||
|
||||
.. rst-class:: classref-section-separator
|
||||
|
||||
----
|
||||
|
||||
.. rst-class:: classref-descriptions-group
|
||||
|
||||
Constants
|
||||
---------
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_OS_MEMORY_WARNING:
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_TRANSLATION_CHANGED:
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_WM_ABOUT:
|
||||
**NOTIFICATION_OS_MEMORY_WARNING** = ``2009``
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_CRASH:
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_OS_IME_UPDATE:
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_APPLICATION_RESUMED:
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_APPLICATION_PAUSED:
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_APPLICATION_FOCUS_IN:
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_APPLICATION_FOCUS_OUT:
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_TEXT_SERVER_CHANGED:
|
||||
|
||||
- **NOTIFICATION_OS_MEMORY_WARNING** = **2009** --- Notification received from the OS when the application is exceeding its allocated memory.
|
||||
Notification received from the OS when the application is exceeding its allocated memory.
|
||||
|
||||
Specific to the iOS platform.
|
||||
|
||||
- **NOTIFICATION_TRANSLATION_CHANGED** = **2010** --- 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 :ref:`Object.tr<class_Object_method_tr>`.
|
||||
.. _class_MainLoop_constant_NOTIFICATION_TRANSLATION_CHANGED:
|
||||
|
||||
- **NOTIFICATION_WM_ABOUT** = **2011** --- Notification received from the OS when a request for "About" information is sent.
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_TRANSLATION_CHANGED** = ``2010``
|
||||
|
||||
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 :ref:`Object.tr<class_Object_method_tr>`.
|
||||
|
||||
.. _class_MainLoop_constant_NOTIFICATION_WM_ABOUT:
|
||||
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_WM_ABOUT** = ``2011``
|
||||
|
||||
Notification received from the OS when a request for "About" information is sent.
|
||||
|
||||
Specific to the macOS platform.
|
||||
|
||||
- **NOTIFICATION_CRASH** = **2012** --- Notification received from Godot's crash handler when the engine is about to crash.
|
||||
.. _class_MainLoop_constant_NOTIFICATION_CRASH:
|
||||
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_CRASH** = ``2012``
|
||||
|
||||
Notification received from Godot's crash handler when the engine is about to crash.
|
||||
|
||||
Implemented on desktop platforms if the crash handler is enabled.
|
||||
|
||||
- **NOTIFICATION_OS_IME_UPDATE** = **2013** --- Notification received from the OS when an update of the Input Method Engine occurs (e.g. change of IME cursor position or composition string).
|
||||
.. _class_MainLoop_constant_NOTIFICATION_OS_IME_UPDATE:
|
||||
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_OS_IME_UPDATE** = ``2013``
|
||||
|
||||
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.
|
||||
|
||||
- **NOTIFICATION_APPLICATION_RESUMED** = **2014** --- Notification received from the OS when the application is resumed.
|
||||
.. _class_MainLoop_constant_NOTIFICATION_APPLICATION_RESUMED:
|
||||
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_APPLICATION_RESUMED** = ``2014``
|
||||
|
||||
Notification received from the OS when the application is resumed.
|
||||
|
||||
Specific to the Android platform.
|
||||
|
||||
- **NOTIFICATION_APPLICATION_PAUSED** = **2015** --- Notification received from the OS when the application is paused.
|
||||
.. _class_MainLoop_constant_NOTIFICATION_APPLICATION_PAUSED:
|
||||
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_APPLICATION_PAUSED** = ``2015``
|
||||
|
||||
Notification received from the OS when the application is paused.
|
||||
|
||||
Specific to the Android platform.
|
||||
|
||||
- **NOTIFICATION_APPLICATION_FOCUS_IN** = **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.
|
||||
.. _class_MainLoop_constant_NOTIFICATION_APPLICATION_FOCUS_IN:
|
||||
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_APPLICATION_FOCUS_IN** = ``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.
|
||||
|
||||
- **NOTIFICATION_APPLICATION_FOCUS_OUT** = **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.
|
||||
.. _class_MainLoop_constant_NOTIFICATION_APPLICATION_FOCUS_OUT:
|
||||
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_APPLICATION_FOCUS_OUT** = ``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.
|
||||
|
||||
- **NOTIFICATION_TEXT_SERVER_CHANGED** = **2018** --- Notification received when text server is changed.
|
||||
.. _class_MainLoop_constant_NOTIFICATION_TEXT_SERVER_CHANGED:
|
||||
|
||||
.. rst-class:: classref-constant
|
||||
|
||||
**NOTIFICATION_TEXT_SERVER_CHANGED** = ``2018``
|
||||
|
||||
Notification received when text server is changed.
|
||||
|
||||
.. rst-class:: classref-section-separator
|
||||
|
||||
----
|
||||
|
||||
.. rst-class:: classref-descriptions-group
|
||||
|
||||
Method Descriptions
|
||||
-------------------
|
||||
|
||||
.. _class_MainLoop_method__finalize:
|
||||
|
||||
- void **_finalize** **(** **)** |virtual|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
void **_finalize** **(** **)** |virtual|
|
||||
|
||||
Called before the program exits.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_MainLoop_method__initialize:
|
||||
|
||||
- void **_initialize** **(** **)** |virtual|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
void **_initialize** **(** **)** |virtual|
|
||||
|
||||
Called once during initialization.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_MainLoop_method__physics_process:
|
||||
|
||||
- :ref:`bool<class_bool>` **_physics_process** **(** :ref:`float<class_float>` delta **)** |virtual|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`bool<class_bool>` **_physics_process** **(** :ref:`float<class_float>` delta **)** |virtual|
|
||||
|
||||
Called each physics frame with the time since the last physics frame as argument (``delta``, in seconds). Equivalent to :ref:`Node._physics_process<class_Node_method__physics_process>`.
|
||||
|
||||
If implemented, the method must return a boolean value. ``true`` ends the main loop, while ``false`` lets it proceed to the next frame.
|
||||
|
||||
.. rst-class:: classref-item-separator
|
||||
|
||||
----
|
||||
|
||||
.. _class_MainLoop_method__process:
|
||||
|
||||
- :ref:`bool<class_bool>` **_process** **(** :ref:`float<class_float>` delta **)** |virtual|
|
||||
.. rst-class:: classref-method
|
||||
|
||||
:ref:`bool<class_bool>` **_process** **(** :ref:`float<class_float>` delta **)** |virtual|
|
||||
|
||||
Called each process (idle) frame with the time since the last process frame as argument (in seconds). Equivalent to :ref:`Node._process<class_Node_method__process>`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user