2026-03-02 04:50:28 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @file main.cpp
|
|
|
|
|
|
* @brief 场景图系统示例程序
|
|
|
|
|
|
*
|
|
|
|
|
|
* 演示 Extra2D 场景图模块的核心功能:
|
|
|
|
|
|
* - Director 场景管理
|
|
|
|
|
|
* - Scene 场景容器
|
|
|
|
|
|
* - Node 节点层级
|
|
|
|
|
|
* - Component 组件系统
|
|
|
|
|
|
* - Transform 变换(含锚点)
|
|
|
|
|
|
* - Camera 相机
|
|
|
|
|
|
* - SpriteRenderer 精灵渲染
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "game_scene.h"
|
|
|
|
|
|
#include <cstdio>
|
2026-03-03 19:41:20 +08:00
|
|
|
|
#include <extra2d.h>
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
|
|
|
|
|
using namespace extra2d;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 程序入口
|
|
|
|
|
|
*/
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2026-03-03 19:41:20 +08:00
|
|
|
|
// ========================================
|
|
|
|
|
|
// 1. 创建应用
|
|
|
|
|
|
// ========================================
|
|
|
|
|
|
auto app = Application::create();
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
AppConfig config;
|
|
|
|
|
|
config.title = "Scene Graph Demo - Extra2D";
|
|
|
|
|
|
config.width = 1280;
|
|
|
|
|
|
config.height = 720;
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
if (!app->init(config)) {
|
|
|
|
|
|
printf("Failed to initialize application!\n");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
// ========================================
|
|
|
|
|
|
// 2. 获取场景模块和导演
|
|
|
|
|
|
// ========================================
|
|
|
|
|
|
SceneModule *sceneModule = app->getModule<SceneModule>();
|
|
|
|
|
|
if (!sceneModule) {
|
|
|
|
|
|
printf("Failed to get SceneModule!\n");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
Director *director = sceneModule->getDirector();
|
|
|
|
|
|
if (!director) {
|
|
|
|
|
|
printf("Failed to get Director!\n");
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
printf("Scene module and director ready\n");
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
// ========================================
|
|
|
|
|
|
// 3. 创建并运行游戏场景
|
|
|
|
|
|
// ========================================
|
|
|
|
|
|
auto gameScene = makePtr<GameScene>();
|
|
|
|
|
|
director->runScene(gameScene);
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
printf("Game scene started\n");
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
// ========================================
|
|
|
|
|
|
// 4. 运行应用主循环
|
|
|
|
|
|
// ========================================
|
|
|
|
|
|
app->run();
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
// ========================================
|
|
|
|
|
|
// 5. 清理(自动进行)
|
|
|
|
|
|
// ========================================
|
|
|
|
|
|
printf("Application shutting down...\n");
|
2026-03-02 04:50:28 +08:00
|
|
|
|
|
2026-03-03 19:41:20 +08:00
|
|
|
|
return 0;
|
2026-03-02 04:50:28 +08:00
|
|
|
|
}
|