0 votes

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

Image1
Image2

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

Godot version 3.2.3
in Engine by (16 points)

2 Answers

+1 vote

https://docs.godotengine.org/en/stable/classes/class_image.html#class-image

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 )

by (846 points)
0 votes

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.

by (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.