This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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?

in Engine by (483 points)

1 Answer

0 votes

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.

by (217 points)

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.

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

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...

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.