How do you detect the difference between a 2D node's position and the edge of the screen?

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

I want to make a dialogue bubble which dynamically sizes, so I want to start by checking how close it is to the edge of the screen.

Is there any way to check the x position of the left/right side of the screen? And from there can I do math on it to find the difference in position? I can’t find documentation on it anywhere.

why do you need it? For different screen sizes?

ramazan | 2022-01-25 08:01

That’s one half of it (so that I can reuse it in any game I make) but the second part is I need to tell where the camera is in the world so that I can, y’know, do the math on it to calculate the edges of the screen.

IntangibleMatter | 2022-01-25 08:03

This feature is available for different screen sizes
Size and anchors — Godot Engine (stable) documentation in English
But I have no idea for the other problem, sorry. I think it might be more appropriate to find different solutions.

ramazan | 2022-01-25 08:59

:bust_in_silhouette: Reply From: skysphr

Canvas items have get_viewport_rect() and get_viewport_transform(). For a more general way to get your data you can call get_viewport() from any node and access its properties.

To be fair, most of the time it’s quite enough to simply use canvas items’ margin features and containers.

skysphr | 2022-01-25 08:52