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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
<?xml version="1.0" encoding="UTF-8" ?>
<class name="MainLoop" inherits="Object" category="Core" version="3.2">
<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 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.
Here is an example script implementing a simple [MainLoop]:
[codeblock]
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))
[/codeblock]
</description>
<tutorials>
</tutorials>
<methods>
<method name="_drop_files" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="files" type="PoolStringArray">
</argument>
<argument index="1" name="from_screen" type="int">
</argument>
<description>
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.
</description>
</method>
<method name="_finalize" qualifiers="virtual">
<return type="void">
</return>
<description>
Called before the program exits.
</description>
</method>
<method name="_idle" qualifiers="virtual">
<return type="bool">
</return>
<argument index="0" name="delta" type="float">
</argument>
<description>
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.
</description>
</method>
<method name="_initialize" qualifiers="virtual">
<return type="void">
</return>
<description>
Called once during initialization.
</description>
</method>
<method name="_input_event" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="event" type="InputEvent">
</argument>
<description>
Called whenever an [InputEvent] is received by the main loop.
</description>
</method>
<method name="_input_text" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="text" type="String">
</argument>
<description>
Deprecated callback, does not do anything. Use [method _input_event] to parse text input. Will be removed in Godot 4.0.
</description>
</method>
<method name="_iteration" qualifiers="virtual">
<return type="bool">
</return>
<argument index="0" name="delta" type="float">
</argument>
<description>
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.
</description>
</method>
<method name="finish">
<return type="void">
</return>
<description>
Should not be called manually, override [method _finalize] instead. Will be removed in Godot 4.0.
</description>
</method>
<method name="idle">
<return type="bool">
</return>
<argument index="0" name="delta" type="float">
</argument>
<description>
Should not be called manually, override [method _idle] instead. Will be removed in Godot 4.0.
</description>
</method>
<method name="init">
<return type="void">
</return>
<description>
Should not be called manually, override [method _initialize] instead. Will be removed in Godot 4.0.
</description>
</method>
<method name="input_event">
<return type="void">
</return>
<argument index="0" name="event" type="InputEvent">
</argument>
<description>
Should not be called manually, override [method _input_event] instead. Will be removed in Godot 4.0.
</description>
</method>
<method name="input_text">
<return type="void">
</return>
<argument index="0" name="text" type="String">
</argument>
<description>
Should not be called manually, override [method _input_text] instead. Will be removed in Godot 4.0.
</description>
</method>
<method name="iteration">
<return type="bool">
</return>
<argument index="0" name="delta" type="float">
</argument>
<description>
Should not be called manually, override [method _iteration] instead. Will be removed in Godot 4.0.
</description>
</method>
</methods>
<constants>
<constant name="NOTIFICATION_WM_MOUSE_ENTER" value="1002">
Notification received from the OS when the mouse enters the game window.
Implemented on desktop and web platforms.
</constant>
<constant name="NOTIFICATION_WM_MOUSE_EXIT" value="1003">
Notification received from the OS when the mouse leaves the game window.
Implemented on desktop and web platforms.
</constant>
<constant name="NOTIFICATION_WM_FOCUS_IN" value="1004">
Notification received from the OS when the game window is focused.
Implemented on all platforms.
</constant>
<constant name="NOTIFICATION_WM_FOCUS_OUT" value="1005">
Notification received from the OS when the game window is unfocused.
Implemented on all platforms.
</constant>
<constant name="NOTIFICATION_WM_QUIT_REQUEST" value="1006">
Notification received from the OS when a quit request is sent (e.g. closing the window with a "Close" button or Alt+F4).
Implemented on desktop platforms.
</constant>
<constant name="NOTIFICATION_WM_GO_BACK_REQUEST" value="1007">
Notification received from the OS when a go back request is sent (e.g. pressing the "Back" button on Android).
Specific to the Android platform.
</constant>
<constant name="NOTIFICATION_WM_UNFOCUS_REQUEST" value="1008">
Notification received from the OS when an unfocus request is sent (e.g. another OS window wants to take the focus).
No supported platforms currently send this notification.
</constant>
<constant name="NOTIFICATION_OS_MEMORY_WARNING" value="1009">
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="1010">
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="1011">
Notification received from the OS when a request for "About" information is sent.
Specific to the macOS platform.
</constant>
<constant name="NOTIFICATION_CRASH" value="1012">
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="1013">
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>
</constants>
</class>
|