#include "hello_module.h" #include using namespace extra2d; /** * @brief 自定义场景类 * * 展示如何在场景中使用自定义模块 */ class HelloScene : public Scene { public: static Ptr create() { return makeShared(); } void onEnter() override { Scene::onEnter(); addListener(EventType::KeyPress, [](Event &e) { auto &keyEvent = std::get(e.data); auto app = Application::get().getModule(); E2D_LOG_INFO("Module {}", app->getName()); if (keyEvent.scancode == static_cast(Key::Escape)) { e.handled = true; E2D_LOG_INFO("ESC pressed, exiting..."); Application::get().quit(); } }); E2D_LOG_INFO("HelloScene entered"); setBackgroundColor(Color(0.1f, 0.1f, 0.2f, 1.0f)); } private: }; /** * @brief 应用程序入口 * * 静态链接时模块直接编译到可执行文件,自动注册,无需任何额外代码! */ int main(int argc, char *argv[]) { (void)argc; (void)argv; Application &app = Application::get(); AppConfig appConfig; appConfig.appName = "HelloModule Example"; appConfig.appVersion = "1.0.0"; if (!app.init(appConfig)) { E2D_LOG_ERROR("Failed to initialize application"); return 1; } auto scene = HelloScene::create(); app.enterScene(scene); app.run(); return 0; }