How to display (multiple sprites) in imageTexture - or other way

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

Hello all,

I have objects in my scene which have all the same tree:
A StaticBody2D Node with 1-x Sprites as childs (pixel based, all sprites are 32px*32px region from a big spritesheet).
E.g. a door with upper and lower sprite, but it could be that the there are more than 1 or 2 sprites (6 for a shelf or something).

So what I want to achieve: When the player is near one of these objects and presses enter I want to show information about that object (description, name etc.) in a popup container.
AND the root of my question is if it is possible to show the sprites of the object as imageTexture/image/whatever by code.
So I know the sprites, I know there size and region position (so theoretically I can calc the new image from the sprites) so but I don’t know how I can merge these sprites into one image/texture/whatever.

In my images you can see on the first one the node with it’s 2 sprites (left door/right door). In second screen you see the popup. Currently I just show a default door image on the right in a ImageTexture, but it would be nice to see the sprites instead of the default image


Does anybody has an idea if this possible at all? I don’t even know how to search for that.
I’ve tried to add a TextureRect for each sprite, but then I don’t know how I can only set the sprite region from the spritesheet as texcture.
Thanks and regards

Edit: After some new research I found a possible solution to use viewports and add the sprites as child…I will check that out

Link on reddit

:bust_in_silhouette: Reply From: yrtv

First calculate size of new image to store your images, then create it with create ( int width, int height, bool use_mipmaps, Format format ).

Then fill it with blit_rect ( Image src, Rect2 src_rect, Vector2 dst )

:bust_in_silhouette: Reply From: Skuriles

Thanks for help,
I found a different solution which works.
I use a viewport in a viewportcontainer and just add copy the sprites with their position as they are in the original Node and add them to this viewport.

I have to remove “centered” flag for all sprites to get absolute positions, but this was not big deal.