I'm trying to make a 2D endless runner.
I want to set up a few scenes of obstacles and then spawn the scenes in a random order. But the game lags whenever I spawn a scene that has more than a few obstacles in it.
I'm completely new to this so the answer might be obvious. But is there any way to improve performance without decreasing the amount of nodes in each scene that I'm spawning?
Here is the code for my spawner:
export (Array,PackedScene) var scenes
var random_scene = RandomNumberGenerator.new()
var selected_scene_index = 0
func _ready():
random_scene.randomize()
selected_scene_index = random_scene.randi_range(0,scenes.size()-1)
var tmp = scenes[selected_scene_index].instance()
add_child_below_node(self,tmp)
func _on_Area2D_area_exited(area):
random_scene.randomize()
selected_scene_index = random_scene.randi_range(0,scenes.size()-1)
var tmp = scenes[selected_scene_index].instance()
add_child_below_node(self,tmp)
Thanks for the help!