0 votes

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.

in Engine by (46 points)

2 Answers

+1 vote
Best answer

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

by (10,475 points)
selected by

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.

+1 vote

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")
by (512 points)

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.