Hi, I´m trying to delete an scene through the pause menu to return to the main menu, but if I tried to return to the level, it keeps the older elements in a lower layer or something like that.
Even that, sometimes it tells me that the player is a null element...
This is the code of the Pause Menu:
extends CanvasLayer
var is_paused = false setget set_paused
func set_paused(value):
is_paused = value
get_tree().paused = is_paused
visible = is_paused
func _on_PlayerHUD_pause_button():
self.is_paused = !is_paused
func _unhandled_key_input(event):
if event.is_action_pressed("pause_game"):
if $SettingsMenu.visible == true:
return
else:
self.is_paused = !is_paused
func _on_ResumeGameButton_pressed():
Select1.play()
self.is_paused = !is_paused
func _on_ExitGameButton_pressed():
Select2.play()
self.is_paused = !is_paused
get_parent().queue_free()
BackgroundMusic.stream = load("res://assets/sounds/music/loops/Menus_Music.mp3")
BackgroundMusic.playing = true
get_tree().change_scene("res://menus/main_menus/MainMenu.tscn")
func _on_OptionsButton_pressed():
Select1.play()
$SettingsMenu.show()
And this is from the main level, it is still under development
extends Node
export(PackedScene) var enemy_ship_scene
signal game_over
# signal time_added
var total_enemies
var score
var lives
func _ready():
BackgroundMusic.stream = load("res://assets/sounds/music/loops/Game_Music.mp3")
BackgroundMusic.playing = true
lives = GlobalVariables.difficulty_selected
func _on_PlayerHUD_start_game():
score = 0
total_enemies = 0
$Player.start($PlayerSpawnLocation.position)
$ScoreUpdateTimer.start()
$GameTimerDuration.start()
$PlayerHUD.update_lives(lives)
$PlayerHUD.update_score(score)
$PlayerHUD.update_timer_duration(floor($GameTimerDuration.time_left))
$PlayerHUD.update_ammo($Player.ammo)
$EnemyShipTimer.start()
func _on_ScoreUpdateTimer_timeout():
score += 1
$PlayerHUD.update_score(score)
$PlayerHUD.update_timer_duration(floor($GameTimerDuration.time_left))
func _input(event):
if event.is_action_pressed("shoot"):
if $Player.ammo > 0:
$PlayerHUD.update_ammo($Player.ammo -1)
else:
return
func _on_Player_reload_complete():
$PlayerHUD.update_ammo($Player.ammo)
The pause menu is instantiated in the level.