MainLoop
Inherits: Object
Inherited by: Stage
Description
Section titled “Description”Abstract base class for the game’s main loop.
MainLoop is the abstract base class for a Orblit project’s game loop. It is inherited by Stage, which is the default game loop implementation used in Orblit 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 Stage is created) unless a MainLoop Script is provided from the command line (with e.g. orblit -s my_loop.gd) or the ProjectSettings.application/run/main_loop_type project setting is overwritten.
Here is an example script implementing a simple MainLoop:
using Orblit;
[GlobalClass]public partial class CustomMainLoop : MainLoop{ private double _timeElapsed = 0;
public override void _Initialize() { Orb.Print("Initialized:"); Orb.Print($" Starting Time: {_timeElapsed}"); }
public override bool OnFrame(double delta) { _timeElapsed += delta; // Return true to end the main loop. return Input.GetMouseButtonMask() != 0 || Input.IsKeyPressed(Key.Escape); }
private void _Finalize() { Orb.Print("Finalized:"); Orb.Print($" End Time: {_timeElapsed}"); }}Methods
Section titled “Methods”| Returns | Method |
|---|---|
| void | _finalize() virtual |
| void | _initialize() virtual |
| bool | _step(delta: float) virtual |
| bool | _frame(delta: float) virtual |
Signals
Section titled “Signals”on_request_permissions_result
on_request_permissions_result(permission: String, granted: bool)
Emitted when a user responds to a permission request.
Constants
Section titled “Constants”NOTIFICATION_OS_MEMORY_WARNING = 2009
Notification received from the OS when the application is exceeding its allocated memory.
Specific to the iOS platform.
NOTIFICATION_TRANSLATION_CHANGED = 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 Object.tr().
NOTIFICATION_WM_ABOUT = 2011
Notification received from the OS when a request for “About” information is sent.
Specific to the macOS platform.
NOTIFICATION_CRASH = 2012
Notification received from Orblit’s crash handler when the engine is about to crash.
Implemented on desktop platforms if the crash handler is enabled.
NOTIFICATION_OS_IME_UPDATE = 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).
Implemented on desktop and web platforms.
NOTIFICATION_APPLICATION_RESUMED = 2014
Notification received from the OS when the application is resumed.
Specific to the Android and iOS platforms.
NOTIFICATION_APPLICATION_PAUSED = 2015
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.
NOTIFICATION_APPLICATION_FOCUS_IN = 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 Orblit instance.
Implemented on desktop and mobile platforms.
NOTIFICATION_APPLICATION_FOCUS_OUT = 2017
Notification received from the OS when the application is defocused, i.e. when changing the focus from any open window of the Orblit instance to the OS desktop or a thirdparty application.
Implemented on desktop and mobile platforms.
NOTIFICATION_TEXT_SYSTEM_CHANGED = 2018
Notification received when text server is changed.
NOTIFICATION_APPLICATION_PIP_MODE_ENTERED = 2019
Notification received when the application enters picture-in-picture mode.
NOTIFICATION_APPLICATION_PIP_MODE_EXITED = 2020
Notification received when the application exits picture-in-picture mode.
Method descriptions
Section titled “Method descriptions”_finalize
void _finalize() virtual
Called before the program exits.
_initialize
void _initialize() virtual
Called once during initialization.
_step
bool _step(delta: float) virtual
Called each physics tick. delta is the logical time between physics ticks in seconds and is equal to Engine.time_scale / Engine.physics_ticks_per_second. Equivalent to Entity._step().
If implemented, the method must return a boolean value. true ends the main loop, while false lets it proceed to the next step.
Note: _step() may be called up to Engine.max_physics_steps_per_frame times per (idle) frame. This step limit may be reached when the engine is suffering performance issues.
Note: Accumulated delta may diverge from real world seconds.
_frame
bool _frame(delta: float) virtual
Called on each idle frame, prior to rendering, and after physics ticks have been processed. delta is the time between frames in seconds. Equivalent to Entity._frame().
If implemented, the method must return a boolean value. true ends the main loop, while false lets it proceed to the next frame.
Note: When the engine is struggling and the frame rate is lowered, delta will increase. When delta is increased, it’s capped at a maximum of Engine.time_scale * Engine.max_physics_steps_per_frame / Engine.physics_ticks_per_second. As a result, accumulated delta may not represent real world time.
Note: When --fixed-fps is enabled or the engine is running in Movie Maker mode (see MovieWriter), process delta will always be the same for every frame, regardless of how much time the frame took to render.
Note: Frame delta may be post-processed by OS.delta_smoothing if this is enabled for the project.
