Hi,
I've been trying to create some borders for my game, but I'm facing some kind of scaling issue. I want to create my borders using RectangleShape2D, which extents across the width of the game window at the top and bottom edges. The problem I'm facing is that the borders don't position or extent like I hoped they would. The bottom border is placed at half the window height and even though the top border is placed correctly, both span only half the window width. Removing the test width makes them extent about 4/5 of the window width and the bottom border positions itself at 3/4 of the window height. I don't know what is causing the problem, but the only thing that has worked so far is setting the windowHeight and windowWidth to 1920 and 1080 manually in DeviceManager.gd.
I have my window size set to 1920 x 1080 and the test window size set to 1024 x 600. Here are the relevant codes:
DeviceManager.gd
class_name DeviceManager
var windowWidth = OS.get_window_size().x
var windowHeight = OS.get_window_size().y
var halfWindowWidth = windowWidth / 2
var halfWindowHeight = windowHeight / 2
BorderClass.gd
class_name BorderClass
extends StaticBody2D
var deviceManager = DeviceManager.new()
export var innerThickness = 0
export var outerThickness = 20
var halfThickness = (innerThickness + outerThickness) / 2
var topBorderPosition = Vector2(deviceManager.halfWindowWidth, innerThickness - halfThickness)
var bottomBorderPosition = Vector2(deviceManager.halfWindowWidth, deviceManager.windowHeight + halfThickness - innerThickness)
var topBorderExtent = Vector2(deviceManager.halfWindowWidth, halfThickness)
var bottomBorderExtent = Vector2(deviceManager.halfWindowWidth, halfThickness)
var topBorder = [topBorderExtent, topBorderPosition]
var bottomBorder = [bottomBorderExtent, bottomBorderPosition]
var borderData = [topBorder, bottomBorder]
Borders.gd
extends BorderClass
var shape
var shapeOwner
func _ready():
create_border()
func create_border():
for data in borderData:
shape = RectangleShape2D.new()
shape.extents = data[0]
shapeOwner = create_shape_owner(self)
shape_owner_set_transform(shapeOwner, Transform2D(0, data[1]))
shape_owner_add_shape(shapeOwner, shape)
I have also attached some pictures to better illustrate where the borders are positioned and end.

I have set the test window size to 1024 x 600 in the first picture and I have remove the test width on the second picture.

As you can see, neither has the bottom border at the edge of the window and neither spans across the window width. Can someone please help me?