2026-02-15 17:00:39 +08:00
|
|
|
#include "hello_module.h"
|
2026-02-15 20:24:32 +08:00
|
|
|
#include <extra2d/extra2d.h>
|
2026-02-15 17:00:39 +08:00
|
|
|
|
|
|
|
|
using namespace extra2d;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 自定义场景类
|
|
|
|
|
*
|
|
|
|
|
* 展示如何在场景中使用自定义模块
|
|
|
|
|
*/
|
|
|
|
|
class HelloScene : public Scene {
|
|
|
|
|
public:
|
|
|
|
|
static Ptr<HelloScene> create() { return makeShared<HelloScene>(); }
|
|
|
|
|
|
|
|
|
|
void onEnter() override {
|
|
|
|
|
Scene::onEnter();
|
2026-02-15 20:24:32 +08:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-02-15 17:00:39 +08:00
|
|
|
E2D_LOG_INFO("HelloScene entered");
|
|
|
|
|
|
|
|
|
|
setBackgroundColor(Color(0.1f, 0.1f, 0.2f, 1.0f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 应用程序入口
|
|
|
|
|
*/
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
|
|
Application &app = Application::get();
|
|
|
|
|
|
2026-02-15 20:13:18 +08:00
|
|
|
HelloModule helloModule;
|
|
|
|
|
app.use(helloModule);
|
|
|
|
|
|
2026-02-15 17:00:39 +08:00
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
app.shutdown();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|