Advertisement
luzdesign

Untitled

Jul 25th, 2023 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Node3D
  2. var http_request = HTTPRequest.new()
  3. var url="https://upload.wikimedia.org/wikipedia/commons/8/85/%22_Shot_From_The_Sky%22_Army_Show_1945_Oak_Ridge_%2824971013612%29.jpg"
  4.  
  5. func _ready():
  6.     http_request = HTTPRequest.new()
  7.     print(http_request.get_http_client_status ())
  8.     add_child(http_request)
  9.  
  10.  
  11.     #http_request.request_resolving.connect(self.reso)
  12.     http_request.request_completed.connect(self._http_request_completed)
  13.  
  14.     var error =  http_request.request(url)
  15.     if error != OK:
  16.         push_error("An error occurred in the HTTP request.")
  17.     print(http_request.get_http_client_status ())
  18.    
  19.        
  20. func _http_request_completed(result, response_code, headers, body):
  21.    
  22.     print(http_request.get_http_client_status ())
  23.     if result != HTTPRequest.RESULT_SUCCESS:
  24.         push_error("Image couldn't be downloaded. Try a different image.")
  25.  
  26.     var image = Image.new()
  27.     var error = image.load_jpg_from_buffer(body)
  28.     if error != OK:
  29.         push_error("Couldn't load the image.")
  30.  
  31.     var texture = ImageTexture.create_from_image(image)
  32.  
  33.     $TextureRect.texture = texture
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement