0 votes

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.

asked Mar 1, 2018 in Engine by TobiLa (167 points)
edited Mar 1, 2018 by TobiLa

1 Answer

+1 vote

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.

answered Mar 1, 2018 by Guilherme Furst (55 points)

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?

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.