Help with get the screen size

Godot Version

The godot version is 4.2.2

Question

I need to get the screen size for generate enemys in the borders of it. I have the logic of the system and I think I’ll need to what is the x dimension and the y dimension. It’s posible?

You can get the current window size with get_viewport().size. (This will return a Vector2)

I think for spawning enemies you might prefer this:

get_viewport.get_visible_rect()

Returns the visible rectangle in global screen coordinates.

the viewport size will be whatever is in your project settings or the size of the viewport on the screen if it has been changed by the user. It won’t take into account cameras or camera zoom or give you coordinates for spawning enemies if your camera moves at all.

In the docs:

It will return a rect which has a start position (Vector2) and a size (Vector2).

But you can see in rect methods lots of useful things like get_center.

1 Like