fix notifier bug, it only effected the exported game

This commit is contained in:
Chris Cromer 2022-09-01 12:26:59 -04:00
parent d560d13627
commit fe9cebc620
Signed by: cromer
GPG Key ID: FA91071797BEEEC2
2 changed files with 17 additions and 3 deletions

View File

@ -51,6 +51,8 @@ void alai::player::Player::_init()
coins = 0;
notifier_initialized = false;
velocity = godot::Vector2();
}
@ -189,11 +191,18 @@ void alai::player::Player::_physics_process(float delta)
auto notifier = get_node<godot::VisibilityNotifier2D>("Camera2D/VisibilityNotifier2D");
if (notifier != nullptr)
{
if (!notifier->is_on_screen())
if (notifier->is_inside_tree() && !notifier->is_on_screen())
{
// 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<alai::Event>("/root/Event");
event->emit_signal("player_died");
}
else {
notifier_initialized = true;
}
}
}
else
{

View File

@ -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:
/**