Skip to content

Commit

Permalink
Adding pause on focus out (#35)
Browse files Browse the repository at this point in the history
* Adding pause on focus out

* Don't show again if already visible
  • Loading branch information
Gravedigger7789 authored Dec 1, 2021
1 parent 0eb8afb commit 78323c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/GUI/GameGUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func _unhandled_input(event: InputEvent) -> void:
get_tree().set_input_as_handled()


func _notification(what: int) -> void:
if what == MainLoop.NOTIFICATION_WM_FOCUS_OUT:
pause_menu.show()


func _on_Player_health_depleted() -> void:
score_gui.save_high_score()
game_over_menu.show()
Expand Down
11 changes: 6 additions & 5 deletions src/GUI/PauseMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ func _ready() -> void:


func show() -> void:
audio_stream_player.stream = pause_sound
audio_stream_player.play()
get_tree().paused = true
continue_button.grab_focus()
.show()
if !visible:
audio_stream_player.stream = pause_sound
audio_stream_player.play()
get_tree().paused = true
continue_button.grab_focus()
.show()


func _on_ContinueButton_pressed() -> void:
Expand Down

0 comments on commit 78323c7

Please sign in to comment.