diff --git a/Extra2D/include/extra2d/app/application.h b/Extra2D/include/extra2d/app/application.h index f5138e1..ac23673 100644 --- a/Extra2D/include/extra2d/app/application.h +++ b/Extra2D/include/extra2d/app/application.h @@ -39,6 +39,9 @@ struct AppConfig { BackendType renderBackend = BackendType::OpenGL; int msaaSamples = 0; PlatformType platform = PlatformType::Auto; + // 窗口高级配置 + bool enableCursors = true; // 是否启用光标 + bool enableDpiScale = false; // 是否启用DPI缩放 }; // ============================================================================ diff --git a/Extra2D/src/animation/frame_renderer.cpp b/Extra2D/src/animation/frame_renderer.cpp index d9d25a4..5e4ce2d 100644 --- a/Extra2D/src/animation/frame_renderer.cpp +++ b/Extra2D/src/animation/frame_renderer.cpp @@ -155,9 +155,9 @@ void FrameRenderer::drawSpriteFrame(RenderBackend &renderer, float flipScaleX = flipX ? -1.0f : 1.0f; float flipScaleY = flipY ? -1.0f : 1.0f; - Rect destRect{ - {finalPos.x - w * 0.5f * flipScaleX, finalPos.y - h * 0.5f * flipScaleY}, - {w, h}}; + // 锚点由 RenderBackend 在绘制时处理,这里只传递位置和尺寸 + // 使用中心锚点(0.5, 0.5),所以 destRect 从 finalPos 开始,不预偏移 + Rect destRect{{finalPos.x, finalPos.y}, {w * flipScaleX, h * flipScaleY}}; Color finalColor{tint.r, tint.g, tint.b, tint.a * opacity}; diff --git a/Extra2D/src/app/application.cpp b/Extra2D/src/app/application.cpp index ac77df3..304c4f6 100644 --- a/Extra2D/src/app/application.cpp +++ b/Extra2D/src/app/application.cpp @@ -93,20 +93,20 @@ bool Application::init(const AppConfig &config) { window_ = makeUnique(); WindowConfig winConfig; winConfig.title = config.title; - winConfig.width = 1280; - winConfig.height = 720; + winConfig.width = config.width; + winConfig.height = config.height; if (platform == PlatformType::Switch) { winConfig.fullscreen = true; winConfig.fullscreenDesktop = false; // Switch 使用固定分辨率全屏 winConfig.resizable = false; - winConfig.enableCursors = false; - winConfig.enableDpiScale = false; + winConfig.enableCursors = config.enableCursors; + winConfig.enableDpiScale = config.enableDpiScale; } else { // PC 平台默认窗口模式 winConfig.fullscreen = config.fullscreen; - winConfig.resizable = true; - winConfig.enableCursors = true; - winConfig.enableDpiScale = true; + winConfig.resizable = config.resizable; + winConfig.enableCursors = config.enableCursors; + winConfig.enableDpiScale = config.enableDpiScale; } winConfig.vsync = config.vsync; winConfig.msaaSamples = config.msaaSamples; diff --git a/Extra2D/src/effects/particle_system.cpp b/Extra2D/src/effects/particle_system.cpp index 48bbb9b..5c9b18a 100644 --- a/Extra2D/src/effects/particle_system.cpp +++ b/Extra2D/src/effects/particle_system.cpp @@ -121,9 +121,8 @@ void ParticleEmitter::render(RenderBackend &renderer) { continue; // 计算目标矩形 - float halfSize = p.size * 0.5f; - Rect destRect(p.position.x - halfSize, p.position.y - halfSize, p.size, - p.size); + // 锚点由 RenderBackend 在绘制时处理,这里只传递位置和尺寸 + Rect destRect(p.position.x, p.position.y, p.size, p.size); renderer.drawSprite( *config_.texture, destRect, diff --git a/Extra2D/src/scene/sprite.cpp b/Extra2D/src/scene/sprite.cpp index 29d53a8..1d3e239 100644 --- a/Extra2D/src/scene/sprite.cpp +++ b/Extra2D/src/scene/sprite.cpp @@ -79,9 +79,8 @@ void Sprite::onDraw(RenderBackend &renderer) { auto pos = getPosition(); auto anchor = getAnchor(); auto scale = getScale(); - Rect destRect(pos.x - width * anchor.x * scale.x, - pos.y - height * anchor.y * scale.y, width * scale.x, - height * scale.y); + // 锚点由 RenderBackend 在绘制时处理,这里只传递位置和尺寸 + Rect destRect(pos.x, pos.y, width * scale.x, height * scale.y); // Adjust source rect for flipping Rect srcRect = textureRect_; @@ -111,9 +110,8 @@ void Sprite::generateRenderCommand(std::vector &commands, auto pos = getPosition(); auto anchor = getAnchor(); auto scale = getScale(); - Rect destRect(pos.x - width * anchor.x * scale.x, - pos.y - height * anchor.y * scale.y, width * scale.x, - height * scale.y); + // 锚点由 RenderBackend 在绘制时处理,这里只传递位置和尺寸 + Rect destRect(pos.x, pos.y, width * scale.x, height * scale.y); // 调整源矩形(翻转) Rect srcRect = textureRect_; diff --git a/xmake.lua b/xmake.lua index 289a705..1d8b574 100644 --- a/xmake.lua +++ b/xmake.lua @@ -91,6 +91,7 @@ if is_config("examples","true") then includes("examples/spatial_index_demo", {rootdir = "examples/spatial_index_demo"}) includes("examples/collision_demo", {rootdir = "examples/collision_demo"}) includes("examples/push_box", {rootdir = "examples/push_box"}) + -- includes("examples/flappy_bird", {rootdir = "examples/flappy_bird"}) end -- ==============================================