Godot Version
4.3
Question
Hello everyone, I need help with my obstacle spawning. The code works, but my obstacles do not appear on the screen. I even used a print statement to debug, but they still won’t appear. In the Remote tab, the obstacles are visible but do not appear on the screen. My scene setup includes a CanvasLayer, a Parallax Background, a Static Ground, a Character2D, and a Camera2D. Any assistance would be appreciated!
func generateObstacles():
# If the obstacles array/list is empty
if obstacles.is_empty() or lastObs.position.x < score + randi_range(100, 500):
# Pick any random obstacle and assign it to the obstacles type variable
var obsType = obstaclesType[randi() % obstaclesType.size()]
var obs
obs = obsType.instantiate()
var obsHeight = obs.get_node("Sprite2D").texture.get_height()
var obsScale = obs.get_node("Sprite2D").scale
var obs_x: int = screen_size.x + score + 100
var obs_y : int = screen_size.y - ground_height - (obsHeight * obsScale.y / 2) + 150
obs.position = Vector2i(obs_x, obs_y)
lastObs = obs
addObstacles(obs, obs_x, obs_y)
func addObstacles(obs, x, y):
obs.position = Vector2i(x, y)
add_child(obs)
obstacles.append(obs)