feat(hello_module): 添加ESC键退出功能
在HelloScene中添加键盘事件监听,当按下ESC键时退出应用。同时简化了头文件引用,使用extra2d.h代替多个单独的头文件。
This commit is contained in:
parent
d06c8735bd
commit
e0adaa3263
|
|
@ -1,8 +1,5 @@
|
|||
#include "hello_module.h"
|
||||
#include <extra2d/app/application.h>
|
||||
#include <extra2d/scene/scene.h>
|
||||
#include <extra2d/services/scene_service.h>
|
||||
#include <extra2d/utils/logger.h>
|
||||
#include <extra2d/extra2d.h>
|
||||
|
||||
using namespace extra2d;
|
||||
|
||||
|
|
@ -17,6 +14,15 @@ public:
|
|||
|
||||
void onEnter() override {
|
||||
Scene::onEnter();
|
||||
addListener(EventType::KeyPressed, [](Event &e) {
|
||||
auto &keyEvent = std::get<KeyEvent>(e.data);
|
||||
|
||||
if (keyEvent.keyCode == static_cast<int>(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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue