Editing Points of Collision box without editor exactly

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By The_Duskitty
:warning: Old Version Published before Godot 3 was released.

Basically i need to make an area around the screen be Surrounded by a Collision box, the problem is, the game is resizeable, so how would i go about doing this in such a way that i can have the Hitbox/collision areas Move with the screen size?

:bust_in_silhouette: Reply From: PixelWizzard

The SceneTree has a signal called screen_resized.
I guess if you get your screen size every time this signal is triggered (you can do this by using get_tree().get_root().get_rect().size) and adjust your Collision box acordingly, you should be fine.

Okay, I have to correct myself. I tried this out myself and I wasn’t able to connect the signal I mentioned before (It exists in the godot help, but seems to be inexistent). what you can do isnsead is call get_tree().get_root().connect("size_changed", self, "your_function") in the _ready()-function of the node you want and do the all the other stuff in the your_function() method.

PixelWizzard | 2016-03-16 20:13

While this is helpful, im trying to figure out how to adjust the collision box itself

The_Duskitty | 2016-03-16 20:15

To do this (while supposing you’re using a rectangleShape2D as your collision box) you can change the size of the given node with this code:

var screen_size = get_tree().get_root().get_rect().size
var shape = get_node("yourCollisionShape2D").get_shape()
shape.set_extents(Vector2(screen_size.x * 2, screen_size.y * 2))

According to the documentation, you have to use twice the size of the rect you want to use, which is why both values are multiplied by two…

PixelWizzard | 2016-03-16 20:43