From f58b920da434c6eb67f7e439277d7fb2eaa4f2e0 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 19 Dec 2024 10:26:55 +0100 Subject: fix player controller responsiveness --- src/example/Player.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/example/Player.cpp b/src/example/Player.cpp index a3126cf..73f0275 100644 --- a/src/example/Player.cpp +++ b/src/example/Player.cpp @@ -11,19 +11,10 @@ using namespace std; class PlayerScript : public Script { public: - void init() { - subscribe( - [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); - } - -private: - bool keypressed(const KeyPressEvent & event) { - if (event.key == Keycode::SPACE) { - Rigidbody & rb = this->get_components_by_name("player").front(); + void update() { + Rigidbody & rb = this->get_components_by_name("player").front(); + if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); - return true; - } - return false; } }; -- cgit v1.2.3