feat(渲染): 添加虚拟分辨率支持并重构相机系统
实现虚拟分辨率渲染系统,支持不同缩放模式 重构相机控制器以使用虚拟分辨率计算可见区域 移除硬编码的屏幕尺寸,改为动态获取 添加分辨率状态管理及相关工具函数 更新窗口和渲染器以处理分辨率变化
This commit is contained in:
@@ -45,7 +45,7 @@ private:
|
||||
bool debugEnabled_ = false;
|
||||
bool initialized_ = false;
|
||||
|
||||
float zoom_ = 1.2f;
|
||||
float zoom_ = 1.0f;
|
||||
float debugMoveSpeed_ = 800.0f;
|
||||
};
|
||||
|
||||
|
||||
@@ -90,9 +90,9 @@ private:
|
||||
int backgroundRepeatWidth_ = 0;
|
||||
/// 地图配置里的整体 Y 偏移;既影响层位置,也影响地板校准。
|
||||
int mapOffsetY_ = 0;
|
||||
bool debugMode_ = true;
|
||||
bool debugMode_ = false;
|
||||
/// 硬编码调试开关:关闭后忽略可行走区域检测,允许角色自由移动。
|
||||
bool movableAreaCheckEnabled_ = false;
|
||||
bool movableAreaCheckEnabled_ = true;
|
||||
/// 当前地图正在播放的背景音乐。
|
||||
Ptr<Music> currentMusic_;
|
||||
};
|
||||
|
||||
@@ -34,9 +34,18 @@ int main(int argc, char **argv) {
|
||||
AppConfig config = AppConfig::createDefault();
|
||||
config.appName = "Frostbite2D Test App";
|
||||
config.appVersion = "1.0.0";
|
||||
#ifdef SWITCH
|
||||
config.windowConfig.width = 1280;
|
||||
config.windowConfig.height = 720;
|
||||
#else
|
||||
config.windowConfig.width = 1066;
|
||||
config.windowConfig.height = 600;
|
||||
#endif
|
||||
config.windowConfig.title = "Frostbite2D - Async Init Demo";
|
||||
config.useVirtualResolution = true;
|
||||
config.virtualWidth = 1066;
|
||||
config.virtualHeight = 600;
|
||||
config.resolutionMode = ResolutionScaleMode::FitHeight;
|
||||
|
||||
Application &app = Application::get();
|
||||
{
|
||||
@@ -76,19 +85,20 @@ int main(int argc, char **argv) {
|
||||
auto LoadingScene = MakePtr<Scene>();
|
||||
SceneManager::get().PushScene(LoadingScene);
|
||||
|
||||
auto Background = Sprite::createFromFile("assets/ImagePacks2/Loading0.jpg");
|
||||
Background->SetSize(1280, 720);
|
||||
auto Background =
|
||||
Sprite::createFromFile("assets/ImagePacks2/Loading0.png");
|
||||
Background->SetSize(1066, 600);
|
||||
LoadingScene->AddChild(Background);
|
||||
|
||||
auto BackgroundBar =
|
||||
Sprite::createFromFile("assets/ImagePacks2/Loading1.png");
|
||||
BackgroundBar->SetPosition(0, 686);
|
||||
BackgroundBar->SetPosition(0 - 107, 566);
|
||||
LoadingScene->AddChild(BackgroundBar);
|
||||
|
||||
auto LoadCircleSp =
|
||||
Sprite::createFromFile("assets/ImagePacks2/Loading2.png");
|
||||
LoadCircleSp->SetAnchor(Vec2(0.5f, 0.5f));
|
||||
LoadCircleSp->SetPosition(1280 / 2.0f, 686 - 60);
|
||||
LoadCircleSp->SetPosition(1066 / 2.0f, 566 - 60);
|
||||
LoadCircleSp->SetBlendMode(BlendMode::Additive);
|
||||
LoadCircleSp->AddUpdateListener([](Actor &self, float dt) {
|
||||
auto rotation = self.GetRotation();
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace frostbite2D {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr float kScreenWidth = 1280.0f;
|
||||
constexpr float kScreenHeight = 720.0f;
|
||||
constexpr int kDebugStickDeadzone = 8000;
|
||||
|
||||
float normalizeControllerAxis(int16 value) {
|
||||
@@ -180,10 +178,10 @@ void GameCameraController::applyFocus() const {
|
||||
return;
|
||||
}
|
||||
|
||||
float halfWidth = kScreenWidth * 0.5f / zoom_;
|
||||
float halfHeight = kScreenHeight * 0.5f / zoom_;
|
||||
Vec2 cameraPos(focus_.x - halfWidth, focus_.y - halfHeight);
|
||||
camera->setZoom(zoom_);
|
||||
float halfWidth = camera->getVisibleWidth() * 0.5f;
|
||||
float halfHeight = camera->getVisibleHeight() * 0.5f;
|
||||
Vec2 cameraPos(focus_.x - halfWidth, focus_.y - halfHeight);
|
||||
camera->setPosition(cameraPos);
|
||||
map_->ApplyCameraFocus(focus_);
|
||||
}
|
||||
|
||||
@@ -43,14 +43,14 @@ void GameMapTestScene::onEnter() {
|
||||
|
||||
{
|
||||
ScopedStartupTrace stageTrace("GameMapTestScene character construction");
|
||||
character_ = MakePtr<CharacterObject>();
|
||||
if (!character_->Construction(0)) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
character_ = MakePtr<CharacterObject>();
|
||||
if (!character_->Construction(0)) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"GameMapTestScene: failed to construct default character");
|
||||
character_.Reset();
|
||||
} else {
|
||||
Vec2 spawnPos =
|
||||
map_->ClampCameraFocus(map_->GetDefaultCameraFocus(), 1.2f);
|
||||
map_->ClampCameraFocus(map_->GetDefaultCameraFocus(), 1.0f);
|
||||
character_->SetCharacterPosition(spawnPos);
|
||||
character_->EnableEventReceive();
|
||||
character_->SetEventPriority(-100);
|
||||
@@ -59,7 +59,6 @@ void GameMapTestScene::onEnter() {
|
||||
}
|
||||
|
||||
cameraController_.SetMap(map_.Get());
|
||||
// cameraController_.SetZoom(1.2f);
|
||||
cameraController_.SetTarget(character_.Get());
|
||||
cameraController_.SetDebugEnabled(false);
|
||||
if (character_) {
|
||||
|
||||
@@ -117,7 +117,6 @@ void GameTown::AddCharacter(RefPtr<Actor> actor, int areaIndex) {
|
||||
|
||||
AddChild(mapIt->map);
|
||||
cameraController_.SetMap(mapIt->map.Get());
|
||||
cameraController_.SetZoom(1.2f);
|
||||
cameraController_.SetTarget(actor.Get());
|
||||
cameraController_.SnapToDefaultFocus();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user