Just a quick question, perhaps easy for some. Below is my code, but I get a warning in the debugger:
W 0:00:03:0021 new_game_menu.gd:324 @ change_country_flag(): Loaded resource as image file, this will not work on export: ‘res://Main/Images/Flags/Afghanistan.png’. Instead, import the image file as an Image resource and load it normally as a resource.
<C++ Source> core/io/image.cpp:2495 @ load()
new_game_menu.gd:324 @ change_country_flag()
new_game_menu.gd:294 @ _on_countries_button_item_selected()
func change_country_flag(country):
var flag_path = "res://Main/Images/Flags/" + country + ".png"
if FileAccess.file_exists(flag_path):
var image = Image.new()
var error = image.load(flag_path)
if error == OK:
var texture = ImageTexture.create_from_image(image)
countryflag.texture = texture
else:
print("Failed to load image: ", flag_path)
else:
print("Flag file does not exist: ", flag_path)
Thank you for the quick answer! Could you please go into more detail? I’m completely new to anything image/textures as most of the work I did until now as all text based or just standard themes. I want to learn as much about it as possible.
func change_country_flag(country):
var flag_path = "res://Main/Images/Flags/" + country + ".png"
if FileAccess.file_exists(flag_path):
var image = Image.new()
var error = load(flag_path)
if error == OK:
var texture = ImageTexture.create_from_image(image)
countryflag.texture = texture
else:
print("Failed to load image: ", flag_path)
else:
print("Flag file does not exist: ", flag_path)
If I do it this way it errors out as Invalid operands ‘Object’ and ‘int’ in operator ‘==’.