From e0adaa3263c9773a5802349d84259d1ebc9fc239 Mon Sep 17 00:00:00 2001 From: ChestnutYueyue <952134128@qq.com> Date: Sun, 15 Feb 2026 20:24:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(hello=5Fmodule):=20=E6=B7=BB=E5=8A=A0ESC?= =?UTF-8?q?=E9=94=AE=E9=80=80=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在HelloScene中添加键盘事件监听,当按下ESC键时退出应用。同时简化了头文件引用,使用extra2d.h代替多个单独的头文件。 --- examples/hello_module/main.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/hello_module/main.cpp b/examples/hello_module/main.cpp index e2d91e0..33cbefe 100644 --- a/examples/hello_module/main.cpp +++ b/examples/hello_module/main.cpp @@ -1,8 +1,5 @@ #include "hello_module.h" -#include -#include -#include -#include +#include using namespace extra2d; @@ -17,6 +14,15 @@ public: void onEnter() override { Scene::onEnter(); + addListener(EventType::KeyPressed, [](Event &e) { + auto &keyEvent = std::get(e.data); + + if (keyEvent.keyCode == static_cast(Key::Escape)) { + e.handled = true; + E2D_LOG_INFO("ESC !!!exit"); + Application::get().quit(); + } + }); E2D_LOG_INFO("HelloScene entered"); setBackgroundColor(Color(0.1f, 0.1f, 0.2f, 1.0f));