Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Karl Wilhelm |
I have an AnimatedSprite node, in which I want to load all .png files from a folder, and add them as frames. So before I can add them as frames I try to use this code to create a list of all files. But when I run this code, it only returns an endless stream of “Found dir: .”, which I assume is the current directory?
extends AnimatedSprite
func _ready():
dir_contents('res://assets/planets')
func dir_contents(path):
var dir = Directory.new()
if dir.open(path) == OK:
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir():
print('Found dir: ' + file_name)
else:
print('Found file: ' + file_name)
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path.")