Documentation
¶
Overview ¶
Package MainLoop provides methods for working with MainLoop object instances.
Index ¶
- Constants
- type Advanced
- type Any
- type Extension
- type ID
- type Implementation
- type Instance
- func (self Instance) AsMainLoop() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) ID() ID
- func (self Instance) OnOnRequestPermissionsResult(cb func(permission string, granted bool), flags ...Signal.Flags)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type Interface
Constants ¶
const NotificationApplicationFocusIn Object.Notification = 2016 //gd:MainLoop.NOTIFICATION_APPLICATION_FOCUS_IN
const NotificationApplicationFocusOut Object.Notification = 2017 //gd:MainLoop.NOTIFICATION_APPLICATION_FOCUS_OUT
const NotificationApplicationPaused Object.Notification = 2015 //gd:MainLoop.NOTIFICATION_APPLICATION_PAUSED
const NotificationApplicationResumed Object.Notification = 2014 //gd:MainLoop.NOTIFICATION_APPLICATION_RESUMED
const NotificationCrash Object.Notification = 2012 //gd:MainLoop.NOTIFICATION_CRASH
const NotificationOsImeUpdate Object.Notification = 2013 //gd:MainLoop.NOTIFICATION_OS_IME_UPDATE
const NotificationOsMemoryWarning Object.Notification = 2009 //gd:MainLoop.NOTIFICATION_OS_MEMORY_WARNING
const NotificationTextServerChanged Object.Notification = 2018 //gd:MainLoop.NOTIFICATION_TEXT_SERVER_CHANGED
const NotificationTranslationChanged Object.Notification = 2010 //gd:MainLoop.NOTIFICATION_TRANSLATION_CHANGED
const NotificationWmAbout Object.Notification = 2011 //gd:MainLoop.NOTIFICATION_WM_ABOUT
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsMainLoop ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Implementation ¶
type Implementation = implementation
Implementation implements Interface with empty methods.
type Instance ¶
[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 [member ProjectSettings.application/run/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;
[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}"); } }
[/csharp] [/codeblocks]
See [Interface] for methods that can be overridden by a [Class] that extends it.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsMainLoop ¶
func (Instance) OnOnRequestPermissionsResult ¶
type Interface ¶
type Interface interface { //Called once during initialization. Initialize() //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. //[b]Note:[/b] [param delta] will be larger than expected if running at a framerate lower than [member Engine.physics_ticks_per_second] / [member Engine.max_physics_steps_per_frame] FPS. This is done to avoid "spiral of death" scenarios where performance would plummet due to an ever-increasing number of physics steps per frame. This behavior affects both [method _process] and [method _physics_process]. As a result, avoid using [param delta] for time measurements in real-world seconds. Use the [Time] singleton's methods for this purpose instead, such as [method Time.get_ticks_usec]. PhysicsProcess(delta Float.X) bool //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. //[b]Note:[/b] [param delta] will be larger than expected if running at a framerate lower than [member Engine.physics_ticks_per_second] / [member Engine.max_physics_steps_per_frame] FPS. This is done to avoid "spiral of death" scenarios where performance would plummet due to an ever-increasing number of physics steps per frame. This behavior affects both [method _process] and [method _physics_process]. As a result, avoid using [param delta] for time measurements in real-world seconds. Use the [Time] singleton's methods for this purpose instead, such as [method Time.get_ticks_usec]. Process(delta Float.X) bool //Called before the program exits. Finalize() }