I am trying to make an infinite scroller game, and I created a signal in the player node that tells the ground and obstacles to stop scrolling when the player dies. It works with the ground node, but for the obstacle node it will stop only if you touch the first spawned in obstacle. If you die from any of the obstacles spawned after, they will keep moving until they despawn at the edge of the screen.
The problem is that every obstacle after the first one doesn't enter the _on_Player_game_over()
function for some reason.
Player code:
func _on_Player_area_entered(_area):
emit_signal("game_over")
$AnimatedSprite.animation = "lost"
lost = true
Obstacle spawning mechanism (located in main node):
func _on_cactusSpawnTimer_timeout():
randomize()
t = rand_range(0,1) #change with score
yield(get_tree().create_timer(t),"timeout")
var cactus = cactus_scene.instance()
add_child(cactus)
func _on_Player_game_over():
$cactusSpawnTimer.stop()
Obstacle code:
func _ready():
position.y = yPos
position.x = xPos
func _process(_delta):
if xPos > 0:
xPos -= speed * 1.33
else:
queue_free()
position.x = xPos
func _on_Player_game_over():
speed = 0