123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/MainLoop.xml.
- .. _class_MainLoop:
- MainLoop
- ========
- **Inherits:** :ref:`Object<class_Object>`
- **Inherited By:** :ref:`SceneTree<class_SceneTree>`
- 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.
- 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 :ref:`ProjectSettings.application/run/main_loop_type<class_ProjectSettings_property_application/run/main_loop_type>` project setting is overwritten.
- Here is an example script implementing a simple **MainLoop**:
- .. tabs::
- .. code-tab:: gdscript
- class_name CustomMainLoop
- extends MainLoop
-
- var time_elapsed = 0
-
- func _initialize():
- print("Initialized:")
- print(" Starting time: %s" % str(time_elapsed))
-
- func _process(delta):
- time_elapsed += delta
- # Return true to end the main loop.
- return Input.get_mouse_button_mask() != 0 || Input.is_key_pressed(KEY_ESCAPE)
-
- func _finalize():
- print("Finalized:")
- print(" End time: %s" % str(time_elapsed))
- .. code-tab:: csharp
- using Godot;
-
- [GlobalClass]
- public partial class CustomMainLoop : MainLoop
- {
- private double _timeElapsed = 0;
-
- public override void _Initialize()
- {
- GD.Print("Initialized:");
- GD.Print($" Starting Time: {_timeElapsed}");
- }
-
- public override bool _Process(double delta)
- {
- _timeElapsed += delta;
- // Return true to end the main loop.
- return Input.GetMouseButtonMask() != 0 || Input.IsKeyPressed(Key.Escape);
- }
-
- private void _Finalize()
- {
- GD.Print("Finalized:");
- GD.Print($" End Time: {_timeElapsed}");
- }
- }
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +-------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | |void| | :ref:`_finalize<class_MainLoop_private_method__finalize>`\ (\ ) |virtual| |
- +-------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | |void| | :ref:`_initialize<class_MainLoop_private_method__initialize>`\ (\ ) |virtual| |
- +-------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`_physics_process<class_MainLoop_private_method__physics_process>`\ (\ delta\: :ref:`float<class_float>`\ ) |virtual| |
- +-------------------------+----------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`_process<class_MainLoop_private_method__process>`\ (\ delta\: :ref:`float<class_float>`\ ) |virtual| |
- +-------------------------+----------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Signals
- -------
- .. _class_MainLoop_signal_on_request_permissions_result:
- .. rst-class:: classref-signal
- **on_request_permissions_result**\ (\ permission\: :ref:`String<class_String>`, granted\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_MainLoop_signal_on_request_permissions_result>`
- 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:
- .. rst-class:: classref-constant
- **NOTIFICATION_OS_MEMORY_WARNING** = ``2009`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_OS_MEMORY_WARNING>`
- Notification received from the OS when the application is exceeding its allocated memory.
- Specific to the iOS platform.
- .. _class_MainLoop_constant_NOTIFICATION_TRANSLATION_CHANGED:
- .. rst-class:: classref-constant
- **NOTIFICATION_TRANSLATION_CHANGED** = ``2010`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_TRANSLATION_CHANGED>`
- 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`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_WM_ABOUT>`
- Notification received from the OS when a request for "About" information is sent.
- Specific to the macOS platform.
- .. _class_MainLoop_constant_NOTIFICATION_CRASH:
- .. rst-class:: classref-constant
- **NOTIFICATION_CRASH** = ``2012`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_CRASH>`
- Notification received from Godot's crash handler when the engine is about to crash.
- Implemented on desktop platforms if the crash handler is enabled.
- .. _class_MainLoop_constant_NOTIFICATION_OS_IME_UPDATE:
- .. rst-class:: classref-constant
- **NOTIFICATION_OS_IME_UPDATE** = ``2013`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_OS_IME_UPDATE>`
- 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.
- .. _class_MainLoop_constant_NOTIFICATION_APPLICATION_RESUMED:
- .. rst-class:: classref-constant
- **NOTIFICATION_APPLICATION_RESUMED** = ``2014`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_APPLICATION_RESUMED>`
- Notification received from the OS when the application is resumed.
- Specific to the Android and iOS platforms.
- .. _class_MainLoop_constant_NOTIFICATION_APPLICATION_PAUSED:
- .. rst-class:: classref-constant
- **NOTIFICATION_APPLICATION_PAUSED** = ``2015`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_APPLICATION_PAUSED>`
- Notification received from the OS when the application is paused.
- Specific to the Android and iOS platforms.
- \ **Note:** On iOS, you only have approximately 5 seconds to finish a task started by this signal. If you go over this allotment, iOS will kill the app instead of pausing it.
- .. _class_MainLoop_constant_NOTIFICATION_APPLICATION_FOCUS_IN:
- .. rst-class:: classref-constant
- **NOTIFICATION_APPLICATION_FOCUS_IN** = ``2016`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_APPLICATION_FOCUS_IN>`
- 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 and mobile platforms.
- .. _class_MainLoop_constant_NOTIFICATION_APPLICATION_FOCUS_OUT:
- .. rst-class:: classref-constant
- **NOTIFICATION_APPLICATION_FOCUS_OUT** = ``2017`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_APPLICATION_FOCUS_OUT>`
- 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 and mobile platforms.
- .. _class_MainLoop_constant_NOTIFICATION_TEXT_SERVER_CHANGED:
- .. rst-class:: classref-constant
- **NOTIFICATION_TEXT_SERVER_CHANGED** = ``2018`` :ref:`🔗<class_MainLoop_constant_NOTIFICATION_TEXT_SERVER_CHANGED>`
- Notification received when text server is changed.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_MainLoop_private_method__finalize:
- .. rst-class:: classref-method
- |void| **_finalize**\ (\ ) |virtual| :ref:`🔗<class_MainLoop_private_method__finalize>`
- Called before the program exits.
- .. rst-class:: classref-item-separator
- ----
- .. _class_MainLoop_private_method__initialize:
- .. rst-class:: classref-method
- |void| **_initialize**\ (\ ) |virtual| :ref:`🔗<class_MainLoop_private_method__initialize>`
- Called once during initialization.
- .. rst-class:: classref-item-separator
- ----
- .. _class_MainLoop_private_method__physics_process:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **_physics_process**\ (\ delta\: :ref:`float<class_float>`\ ) |virtual| :ref:`🔗<class_MainLoop_private_method__physics_process>`
- 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_private_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_private_method__process:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **_process**\ (\ delta\: :ref:`float<class_float>`\ ) |virtual| :ref:`🔗<class_MainLoop_private_method__process>`
- Called each process (idle) frame with the time since the last process frame as argument (in seconds). Equivalent to :ref:`Node._process<class_Node_private_method__process>`.
- If implemented, the method must return a boolean value. ``true`` ends the main loop, while ``false`` lets it proceed to the next frame.
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
- .. |void| replace:: :abbr:`void (No return value.)`
|