MainLoop

Inherits: Object

Inherited By: SceneTree

Clase base abstracta para el bucle principal del juego.

Descripción

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. godot -s my_loop.gd, which should then be a MainLoop implementation.

Here is an example script implementing a simple MainLoop:

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))

Métodos

void

_drop_files ( PoolStringArray files, int from_screen ) virtual

void

_finalize ( ) virtual

void

_global_menu_action ( Variant id, Variant meta ) virtual

bool

_idle ( float delta ) virtual

void

_initialize ( ) virtual

void

_input_event ( InputEvent event ) virtual

void

_input_text ( String text ) virtual

bool

_iteration ( float delta ) virtual

void

finish ( )

bool

idle ( float delta )

void

init ( )

void

input_event ( InputEvent event )

void

input_text ( String text )

bool

iteration ( float delta )

Señales

  • on_request_permissions_result ( String permission, bool granted )

Emitido cuando un usuario responde a una solicitud de permiso.

Constantes

  • NOTIFICATION_WM_MOUSE_ENTER = 1002 --- Notificación recibida del sistema operativo cuando el ratón entra en la ventana del juego.

Implementado en plataformas de escritorio y web.

  • NOTIFICATION_WM_MOUSE_EXIT = 1003 --- Notificación recibida del sistema operativo cuando el ratón sale de la ventana del juego.

Implementado en plataformas de escritorio y web.

  • NOTIFICATION_WM_FOCUS_IN = 1004 --- Notificación recibida del sistema operativo cuando la ventana del juego está enfocada.

Implementado en todas las plataformas.

  • NOTIFICATION_WM_FOCUS_OUT = 1005 --- Notificación recibida del sistema operativo cuando la ventana del juego está desenfocada.

Implementado en todas las plataformas.

  • NOTIFICATION_WM_QUIT_REQUEST = 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.

  • NOTIFICATION_WM_GO_BACK_REQUEST = 1007 --- Notificación recibida del sistema operativo cuando se envía una solicitud de retroceso (por ejemplo, pulsando el botón "Back" en Android).

Específico de la plataforma Android.

  • NOTIFICATION_WM_UNFOCUS_REQUEST = 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.

  • NOTIFICATION_OS_MEMORY_WARNING = 1009 --- Notificación recibida del sistema operativo cuando la aplicación supera su memoria asignada.

Específico de la plataforma iOS.

  • NOTIFICATION_TRANSLATION_CHANGED = 1010 --- Notificación recibida cuando las traducciones pueden haber cambiado. Puede ser activada por el usuario al cambiar el locale. Puede utilizarse para responder a los cambios de idioma, por ejemplo, para cambiar las strings de la interfaz de usuario sobre la marcha. Útil cuando se trabaja con el soporte de traducción incorporado, como Object.tr.

  • NOTIFICATION_WM_ABOUT = 1011 --- Notificación recibida del sistema operativo cuando se envía una solicitud de información "Acerca de".

Específico de la plataforma MacOS.

  • NOTIFICATION_CRASH = 1012 --- Notificación recibida del controlador de fallos de Godot cuando el motor está a punto de fallar.

Implementado en las plataformas de escritorio si el manejador de fallos está habilitado.

  • NOTIFICATION_OS_IME_UPDATE = 1013 --- Notificación recibida del sistema operativo cuando se produce una actualización del motor del método de entrada (por ejemplo, cambio de la posición del cursor de la IME o de la string de composición).

Específico de la plataforma MacOS.

  • NOTIFICATION_APP_RESUMED = 1014 --- Notification received from the OS when the app is resumed.

Specific to the Android platform.

  • NOTIFICATION_APP_PAUSED = 1015 --- Notification received from the OS when the app is paused.

Specific to the Android platform.

Descripciones de Métodos

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.


  • void _finalize ( ) virtual

Llamada previa a la salida del programa.


Called when the user performs an action in the system global menu (e.g. the Mac OS menu bar).


Llamada a cada fotograma ocioso con el tiempo desde el último fotograma ocioso como argumento (en segundos). Equivalente a Node._process.

Si se implementa, el método debe devolver un valor booleano. true termina el bucle principal, mientras que false le permite pasar al siguiente fotograma.


  • void _initialize ( ) virtual

Llamado una vez durante la inicialización.


Called whenever an InputEvent is received by the main loop.


  • void _input_text ( String text ) virtual

Deprecated callback, does not do anything. Use _input_event to parse text input. Will be removed in Godot 4.0.


Called each physics frame with the time since the last physics frame as argument (delta, in seconds). Equivalent to Node._physics_process.

If implemented, the method must return a boolean value. true ends the main loop, while false lets it proceed to the next frame.


  • void finish ( )

No debe llamarse manualmente, en su lugar, anular _finalize. Será eliminado en Godot 4.0.


No se debe llamar manualmente, anular _idle en su lugar. Será eliminado en Godot 4.0.


  • void init ( )

No se debe llamar manualmente, anular _initialize en su lugar. Será eliminado en Godot 4.0.


Should not be called manually, override _input_event instead. Will be removed in Godot 4.0.


  • void input_text ( String text )

Should not be called manually, override _input_text instead. Will be removed in Godot 4.0.


No se debe llamar manualmente, anular iteration en su lugar. Será eliminado en Godot 4.0.