Extra2D/examples/scene_graph_demo/main.cpp

80 lines
2.0 KiB
C++
Raw Normal View History

/**
* @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;
}