That’s because you are chaining calls on assignment of your image and the end result is int (Image.load() returns int).
Try:
var image = Image.new()
image.load("res://image.png")
btw, this should work too:
var image = load("res://image.png")
Ok, changing it from Image.new().load, I instead just used load, which works. However, I still am un-sure about how to apply a texture to a new TextureRect?
DrewS | 2018-03-10 03:02
Well, there’s a mistake in your code. Should be TR.texture not TR.Texture.
KoBeWi | 2018-03-10 13:36
Hi! I’m pretty new with Godot and trying to achieve a similar thing.
I’d like to assign images programmatically to a TextureRect.
However,
var texture = ImageTexture.new()
gives me an error saying Condition '!texture->active' is true. returned: Ref<Image>().
when I try to replace it with
var texture = ImageTexture.create_from_image(image, 7)
it gives me an error saying Invalid call. Nonexistent function 'create_from_image' in base 'GDScriptNativeClass'.
here is my snippet:
var image = Image.new()
image.load("res://image.png")
var texture = ImageTexture.new()
texture.create_from_image(image, 7)
$TextureRect.texture = texture