Godot 4 dev notes
Collection of tips found while making games with the Godot 4 game engine
These may not be the best solutions ever, but these are just the ones that worked for me
Screenshots
Taking screenshot is a common game feature, here is a simple example.
I don't know yet how to save in a standerd folder such as Downloads, this solution saves the file in the user:
location.
Multiple images can be saved as each one has an unique name. A screenshots
sub folder is also created if missing.
func take_screenshot():
var folder = "user://screenshots/"
var img = get_viewport().get_texture().get_image()
if !DirAccess.dir_exists_absolute(folder):
print(DirAccess.make_dir_absolute(folder))
img.save_png(folder + "image-" + str(Time.get_unix_time_from_system()) + ".png" )
The function can be called when waiting for the F12 key:
func _input(event:InputEvent):
if event is InputEventKey:
if event.pressed:
if event.keycode == KEY_F12:
take_screenshot()