Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TheJollyReaper |
I copy pasted the bottom example ('Example of loading and displaying an image using HTTPRequest:) from the docs:
Can’t get it to work. Brand new project, completely empty. Just a single node with that example code and a print statement in the _http_request_completed function to check if the code ever gets there.
It doesn’t.
my full code
extends Node2D
func _ready():
# Create an HTTP request node and connect its completion signal.
var http_request = HTTPRequest.new()
add_child(http_request)
http_request.connect("request_completed", self, "_http_request_completed")
# Perform the HTTP request. The URL below returns a PNG image as of writing.
var error = http_request.request("https://via.placeholder.com/512")
if error != OK:
push_error("An error occurred in the HTTP request.")
print('pie')
# Called when the HTTP request is completed.
func _http_request_completed(result, response_code, headers, body):
var image = Image.new()
var error = image.load_png_from_buffer(body)
if error != OK:
push_error("Couldn't load the image.")
var texture = ImageTexture.new()
texture.create_from_image(image)
# Display the image in a TextureRect node.
var texture_rect = TextureRect.new()
add_child(texture_rect)
texture_rect.texture = texture
print('turtle')