Load lots of resource at run-time

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vonflyhighace2
:warning: Old Version Published before Godot 3 was released.

Is there a way to load a lot of resources at Run-Time. Example if I have a bunch of images I wanted to load into an array/List off of the hard-disk. If not how would I go about doing so?

:bust_in_silhouette: Reply From: Freeman

You could use preloading.
The is a documentation and a simple example:
http://docs.godotengine.org/en/latest/tutorials/step_by_step/resources.html?highlight=preload#loading-resources-from-code

That says (exact copy):

Loading resources from code is easy, there are two ways to do it. The first is to use load(), like this:

func _ready():
        var res = load("res://robi.png") # resource is loaded when line is executed
        get_node("sprite").set_texture(res)

The second way is more optimal, but only works with a string constant parameter, because it loads the resource at compile-time.

func _ready():
        var res = preload("res://robi.png") # resource is loaded at compile time
        get_node("sprite").set_texture(res)

Reading about the background loading might be helpful as well, if you plan to create progress bar for player to see the progress of loading the resources:
http://docs.godotengine.org/en/latest/tutorials/engine/background_loading.html?highlight=preload

Thanks for the reply but not quite what I’m looking for. Maybe I should explain a bit more. I want to load an entire resource folder full of images into an array at run-time. What I want to know is there a way to do this all at once stead of one by one?

vonflyhighace2 | 2016-04-08 23:56

:bust_in_silhouette: Reply From: eaglecat

this is an very simple example of loading resources

var resources = Array()

func simpleLoad(var dirPath):
	var dir = Directory.new()
	dir.open(dirPath)
	dir.list_dir_begin()
	var file_name = dir.get_next()

	while(file_name!=""): 
		if dir.current_is_dir():
			pass
		else:
			resources.append(dirPath+"/"+file_name,file.READ)
		file_name = dir.get_next()