MainLoop
Abstract base class for the game’s main loop.
MainLoop.swift:21class MainLoop
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. godot -s my_loop.gd
or the “Main Loop Type” project setting is overwritten.
Here is an example script implementing a simple MainLoop
:
This object emits the following signals:
Superclasses
class Object
Base class for all other classes in the engine.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
class Signal1
Signal support.
Type members
static let notificationApplicationFocusIn: Int
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.
static let notificationApplicationFocusOut: Int
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.
static let notificationApplicationPaused: Int
Notification received from the OS when the application is paused.
static let notificationApplicationResumed: Int
Notification received from the OS when the application is resumed.
static let notificationCrash: Int
Notification received from Godot’s crash handler when the engine is about to crash.
static let notificationOsImeUpdate: Int
Notification received from the OS when an update of the Input Method Engine occurs (e.g. change of IME cursor position or composition string).
static let notificationOsMemoryWarning: Int
Notification received from the OS when the application is exceeding its allocated memory.
static let notificationTextServerChanged: Int
Notification received when text server is changed.
static let notificationTranslationChanged: Int
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
tr(message:context:)
.static let notificationWmAbout: Int
Notification received from the OS when a request for “About” information is sent.
class var godotClassName: StringName
Instance members
var onRequestPermissionsResult: Signal1
Emitted when a user responds to a permission request.
Show implementation details (4)
Hide implementation details
func _finalize(
) Called before the program exits.
func _initialize(
) Called once during initialization.
func _physicsProcess(delta: Double
) -> Bool Called each physics frame with the time since the last physics frame as argument (
delta
, in seconds). Equivalent to_physicsProcess(delta:)
.func _process(delta: Double
) -> Bool Called each process (idle) frame with the time since the last process frame as argument (in seconds). Equivalent to
_process(delta:)
.
Subclasses
class SceneTree
Manages the game loop via a hierarchy of nodes.