Combine multiple sprites so that I can get the total height and width?

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

Hey,

I am having a basic sprite, which I add some details to during runtime.
I don’t know if this is the best way, but I currently do this by adding the different sprites as childs and setting the local coordinates to get them to the right position.
It is intended that some of them stick out my basic sprite.

I now want to get the height and width of the total thing.

So e.g. if my basic sprite (green shape) is 200 pixels wide, and one detail child sprite sticks out by 50 pixels on the right side (blue shape), I want to get 250 pixels.
enter image description here

It this possible somehow?

PS: Im using Godot 2

Edit: Unfortunately I didn’t mention that I’m actually not using Sprite but Sprite3D.
I thought this way it would be easier to explain and I thought I could just adopt it for my case because Sprite3D and Sprite basically have the same API. Looks like that wasn’t a good decision.

:bust_in_silhouette: Reply From: Guilherme Furst

If they have the same parent, or if the added sprites are child of the primary sprite, you can just get_item_and_children-rect(), which is a method for CanvasItem.
From that, the Rect object represents the area that node and its children occupy on screen, thus you can get their combined Vector2 size.

Great answer, thank you so much!
Unfortunately I didn’t mention that I’m actually not using Sprite but Sprite3D.
I thought this way it would be easier to explain and I thought I could just adopt it for my case because Sprite3D and Sprite basically have the same API. Looks like I am not able to adopt it, because Sprite3D doesn’t inherit from CanvasItem.
Do you have another solution that works for 3D, too?

TobiLa | 2018-03-01 13:59