- Edited
Hi there,
I have a problem since I decided to kinda centralize some data from my scene. As you can see below, I have my root node called GameScreen
It has a script attached which for now just contains some important variables for my game and that other nodes should be able to access and eventually modify. For example, here is the code for the Circle node which draws a simple circle in the middle with the desired radius
extends Node2D
var radius = 0
export var segments = 64
func _ready():
position = $GameScreen.getViewCenter()
func _process(delta):
radius = $GameScreen.getPlayAreaRadius()
func _draw():
drawCircle()
func drawCircle():
var circlePoints = Array()
var stepAngle
for i in range(segments + 1):
stepAngle = (float(i) / segments) * deg2rad(360)
circlePoints.append(Vector2(cos(stepAngle) * radius, sin(stepAngle) * radius))
for i in range (segments):
draw_line(circlePoints[i], circlePoints[i + 1], Color(0.5, 0.5, 0.5), 4, true)
You can see that in the _ready()
and the _process()
functions, I am trying to get the values of the variables storing the center of the view and the radius of the area where the game takes place through the getViewCenter()
and the getPlayAreaRadius()
functions defined in the GameScreen's script. I've replaced $Gamescreen
with everything I know to get access to its functions (get_node(../GameScreen)
, get_tree().get_root()
, GameScreen
) but every time Godot can either not find the node or returns null
The problem it causes is that it launches the game but only a black window shows up and can't be closed unless I kill the process
I'm running out of ideas
Someone please help