How to show two images on screen in gdscript?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Black Monkey

I mean: what is minimaly neccesary, an more importantly why?
I looked at code here and on other sites, but that is always about creating one
image on one textureimage, to save or load or manipulate it in some way.
So I can do that…
So I thought I new it; used it and went on…coding other stuff.
But now I want to do some optimization en bughunting, and realize I don’t really know
this basic step.
(in previous languages showing an image was as easy as: ‘create image(size)… draw image(there)’ .)
So; do I need a node2d, a texturect, a textureimage and?
And if I want to show 2 images needs that all to be doubled?
Thanks for any help, because I feel very confused and dumb.

Not sure if I can follow… If you have a scene (the type of the root-node might vary but for simplicity let’s say it’s a Node2D) and want to display an image in that scene, you would either add a TextureRect-node or a Sprite-node as it’s children. Then in the inspector you have to choose a texture for this node to display. If you want to display two images, you’d create another TextureRect- or Sprite-node and choose a different texture for it, yes. Though I don’t get why that apparently confuses you.

njamster | 2020-08-01 17:58

Yes, well…Thanks for the answer I guess.
In the godot-docs, on the page about image, there is no mention of texturerect, and at texturerect no word about image.
In learning any new skill, its best to know the why, to better comprehend the how.
I appreciate your answer about the how, but the why keeps being elusive.

Black Monkey | 2020-08-01 19:46

In the godot-docs, on the page about image, there is no mention of texturerect, and at texturerect no word about image.

That’s correct. However, Image (like Texture) happens to be a resource. Resources don’t do anything on their own, but are used by Nodes. So no matter what you want to do in Godot, you’ll have to look for a fitting node, not resource. That is introduced right away in section 2 of the “Step by Step”-guide on getting started.

Furthermore the description of Image kicks off with: “Contains image data, which can be converted to a Texture”. And the description of Texture then will tell you that it “can be used in 3D models or 2D Sprite or GUI Control”.

Of course you could argue that typing “Image” in the search field of the docs should show you how to display an image. And I agree that this could be handled better.

but the why keeps being elusive

Why what? Why you have to add two instances of the same node if you want them to display (i.e. do) different things? That’s a design decision. Of course one could do it differently, but personally I find that system incredibly intuitive!

What’s bothering you so much about it?

njamster | 2020-08-01 20:21

First off: I am realy happy that people like you, are helping people like me, who are learning the basics of ( in ths case) godot.
But I am not bothered by the way godot is set up. I like it and it’s the reason I stepped overt
to this game-engine.
My ‘confusion’ is not hard to understand; I say so it in my question: in my head are floating a dozen different concepts of how ‘machine-languages’ put pictures on screen.
And godot just happens to that different.
And the ‘why’ is not why godot does it this or that way, it’s about why one needs a recturerect to show an image.
Knowing a bit more; I would explain it like this: A node2D is like an empty canvas.
For it to show something, that something needs shape and position, provided by a recturerect; and color in the form of a texture. If you want to show an image, you then have to place its texture in the texturerect.
(I would no be surprised if ‘the above’ isn’t even correct, but it’s the thought that counts)

And how to code that, or to do in in the editor, I can figure out by myself… or ask once more. ha!
This is not a be be critical; just telling why I asked the question, the way I did.

It reminds me someway of the story of the boy and the fisherman. The boy asked why he is fishing near the bridge. The fisherman tells a sob-story about his wife and hungry children.
But the boy just wanted to know why near the bridge was better.
So he shouts: aren’t that your wife and children I see in that steer-less boat in the distance?
The fisherman drops all and runs of towards the horizon. The boy picks up the rod and hat and makes himself comfortable on the riverbank.
the end.

Black Monkey | 2020-08-02 00:35