MainLoop 类

MainLoop
继承: Object

继承者: SceneTree

Abstract base class for the game’s main loop.
游戏主循环的抽象基类。

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.
MainLoop是Godot项目的游戏循环的抽象基类。它被SceneTree继承,后者是Godot项目中使用的默认游戏循环实现,不过也可以编写和使用自己的MainLoop子类而不是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.
在应用程序启动时,必须向OS提供一个MainLoop实现;否则,应用程序将退出。除非从命令行提供一个主脚本(例如 godot -s my_loop.gd,它应该是一个 MainLoop 实现),否则这个过程会自动发出(和创建一个 SceneTree)。

Here is an example script implementing a simple MainLoop:
这是实现简单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))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值