1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<?xml version="1.0" encoding="UTF-8" ?>
<class name="MainLoop" inherits="Object" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Abstract base class for the game's main loop.
</brief_description>
<description>
[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 [MainLoop] [Script] is provided from the command line (with e.g. [code]godot -s my_loop.gd[/code] or the "Main Loop Type" project setting is overwritten.
Here is an example script implementing a simple [MainLoop]:
[codeblocks]
[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))
[/gdscript]
[csharp]
using Godot;
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}");
}
}
[/csharp]
[/codeblocks]
</description>
<tutorials>
</tutorials>
<methods>
<method name="_finalize" qualifiers="virtual">
<return type="void" />
<description>
Called before the program exits.
</description>
</method>
<method name="_initialize" qualifiers="virtual">
<return type="void" />
<description>
Called once during initialization.
</description>
</method>
<method name="_physics_process" qualifiers="virtual">
<return type="bool" />
<param index="0" name="delta" type="float" />
<description>
Called each physics frame with the time since the last physics frame as argument ([param delta], 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.
</description>
</method>
<method name="_process" qualifiers="virtual">
<return type="bool" />
<param index="0" name="delta" type="float" />
<description>
Called each process (idle) frame with the time since the last process 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.
</description>
</method>
</methods>
<signals>
<signal name="on_request_permissions_result">
<param index="0" name="permission" type="String" />
<param index="1" name="granted" type="bool" />
<description>
Emitted when a user responds to a permission request.
</description>
</signal>
</signals>
<constants>
<constant name="NOTIFICATION_OS_MEMORY_WARNING" value="2009">
Notification received from the OS when the application is exceeding its allocated memory.
Specific to the iOS platform.
</constant>
<constant name="NOTIFICATION_TRANSLATION_CHANGED" value="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 [method Object.tr].
</constant>
<constant name="NOTIFICATION_WM_ABOUT" value="2011">
Notification received from the OS when a request for "About" information is sent.
Specific to the macOS platform.
</constant>
<constant name="NOTIFICATION_CRASH" value="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.
</constant>
<constant name="NOTIFICATION_OS_IME_UPDATE" value="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.
</constant>
<constant name="NOTIFICATION_APPLICATION_RESUMED" value="2014">
Notification received from the OS when the application is resumed.
Specific to the Android platform.
</constant>
<constant name="NOTIFICATION_APPLICATION_PAUSED" value="2015">
Notification received from the OS when the application is paused.
Specific to the Android platform.
</constant>
<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>
<constant name="NOTIFICATION_TEXT_SERVER_CHANGED" value="2018">
Notification received when text server is changed.
</constant>
</constants>
</class>
|