How to download and load a file as texture into a Sprite node using HttpRequest ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sanjib

I want to download image from a particular http path using httpRequest and load that image as texture on a Sprite Node.

Thanks in advance.

:bust_in_silhouette: Reply From: fpicoral

I’m not sure if you can do that. I managed to download the image but it only appears on the project files after restarting the game. Try yourself with the code below:

func download_texture(url : String, file_name : String):
	var http = HTTPRequest.new()
	add_child(http)
	http.set_download_file(file_name)
	http.request(url)

func _ready():
	download_texture("https://opengameart.org/sites/default/files/player_19.png", "my_new_texture.png")

Thanks for your answer, but the answer below is perfect.

sanjib | 2019-02-16 08:08

This is exactly what I was looking for. Thank you!

jackgriffith03 | 2021-08-07 01:40

:bust_in_silhouette: Reply From: Calinou

This is demonstrated in Unpackaged images question, just replace the TextureRect node with a Sprite.

Thank You it worked. i have two questions, if we want jpg images to download, is there any function for that? and second is how to show a loading image that it is downloading.

sanjib | 2019-02-16 08:07