openlang

怎样获取 Godot 系统时间来制作数字时钟?

我在给游戏制作数字时钟,需要把当前时间(小时和分钟)显示成 HH:MM:SS 这样的格式。应该从哪里取得所需的时间值?

从英语翻译查看原文

后续讨论 2

顺着彼此的依据读下去
  1. 固定链接

    Time (https://docs.godotengine.org/en/stable/classes/class_time.html) 单例提供 get_datetime_dict_from_system (https://docs.godotengine.org/en/stable/classes/class_time.html#class-time-method-get-datetime-dict-from-system),它会返回一个字典,包含从系统时钟取得的时间信息。

    # Read a dictionary of clock fields
    var clock_fields = Time.get_time_dict_from_system()
    
    print(clock_fields) # {day:X, dst:False, hour:xx, minute:xx, month:xx, second:xx, weekday:x, year:xxxx}

    对于你的 HH:MM 格式,更简单的 get_time_dict_from_system (https://get_time_dict_from_system) 只返回小时、分钟和秒字段

    var clock_fields = Time.get_time_dict_from_system()
    
    # Format each field with 2 zero-padded digits, e.g. 02:31:24
    print("%02d:%02d:%02d" % [clock_fields.hour, clock_fields.minute, clock_fields.second])

    在较早的 Godot 版本(-3.4)中,也可以调用 OS.get_time() (https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-get-time),但它在 3.5+ 中已弃用,在 4.x 中已移除。

    从英语翻译查看原文

同一个问题的其他角度

  1. gdb 能否按地址在汇编指令处设置断点?

    我的尝试如下。 不过,看起来并不存在这条命令。 gdb 能实现这样的功能吗?

    回复 2最近活动 assembly
  2. Playwright 断言能否允许两个文本值中的任意一个?

    我想验证文本中包含 one 或 two。 在 Playwright 中能这样实现吗? 同样的写法也能用在句子内部吗,比如下面这样

    回复 2最近活动 typescript
  3. 为什么 TsLint 要求为这个函数的 callSignature 指定返回类型?

    我的代码中有下面这个函数。 TsLint 对它报告了这个错误。 有人能解释一下这条消息的含义吗?

    回复 2最近活动 typescript