Skip to content

Instantly share code, notes, and snippets.

@DeerTears
Created August 15, 2020 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeerTears/e1f8b979314c9d7de0b5ca62676be5e3 to your computer and use it in GitHub Desktop.
Save DeerTears/e1f8b979314c9d7de0b5ca62676be5e3 to your computer and use it in GitHub Desktop.
time-handling singleton for Godot
extends Node
var start_time = OS.get_ticks_msec()
func reset_time():
start_time = OS.get_ticks_msec()
func get_time() -> int:
return (OS.get_ticks_msec() - start_time)
func convert_msec_to_timestamp(msec:int) -> String:
var minutes: float = floor(float(msec) / 60000)
# warning-ignore:narrowing_conversion
var remainder: int = msec - (minutes * 60000)
# warning-ignore:integer_division
var seconds: int = remainder / 1000
var milli: int = remainder - (seconds * 1000)
return "%s:%s.%s" % [minutes, seconds, milli]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment