Extra2D/examples/scene_graph_demo/main.cpp

80 lines
2.0 KiB
C++

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