From fe9cebc620de7f0a496b8592a82f252f70410ada Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 1 Sep 2022 12:26:59 -0400 Subject: [PATCH] fix notifier bug, it only effected the exported game --- src/player/Player.cpp | 15 ++++++++++++--- src/player/Player.h | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/player/Player.cpp b/src/player/Player.cpp index fc3336c..9a128f9 100644 --- a/src/player/Player.cpp +++ b/src/player/Player.cpp @@ -51,6 +51,8 @@ void alai::player::Player::_init() coins = 0; + notifier_initialized = false; + velocity = godot::Vector2(); } @@ -189,10 +191,17 @@ void alai::player::Player::_physics_process(float delta) auto notifier = get_node("Camera2D/VisibilityNotifier2D"); if (notifier != nullptr) { - if (!notifier->is_on_screen()) + if (notifier->is_inside_tree() && !notifier->is_on_screen()) { - auto event = get_node("/root/Event"); - event->emit_signal("player_died"); + // The first time the notifier is checked always returns false in the first frame + // So skip the check from the first frame + if (notifier_initialized) { + auto event = get_node("/root/Event"); + event->emit_signal("player_died"); + } + else { + notifier_initialized = true; + } } } else diff --git a/src/player/Player.h b/src/player/Player.h index ee9067d..578840a 100644 --- a/src/player/Player.h +++ b/src/player/Player.h @@ -117,6 +117,11 @@ namespace alai * */ bool double_jump; + /** + * @brief If the notifier for the player being on screen has been initialized or not. + * + */ + bool notifier_initialized; public: /**