diff --git a/DungeonShooting_Godot/src/game/GameApplication.cs b/DungeonShooting_Godot/src/game/GameApplication.cs index 35272b1..85a1beb 100644 --- a/DungeonShooting_Godot/src/game/GameApplication.cs +++ b/DungeonShooting_Godot/src/game/GameApplication.cs @@ -106,7 +106,6 @@ //固定帧率 //Engine.MaxFps = TargetFps; //调试绘制开关 - //IsDebug = true; ActivityObject.IsDebug = false; //Engine.TimeScale = 0.2f; //调整窗口分辨率 @@ -183,8 +182,7 @@ /// public Vector2 GlobalToViewPosition(Vector2 globalPos) { - //return globalPos; - return globalPos / PixelScale - (ViewportSize / 2) + GameCamera.Main.GlobalPosition; + return globalPos / PixelScale - (ViewportSize / 2) + GameCamera.Main.GlobalPosition - GameCamera.Main.PixelOffset; } /// @@ -192,9 +190,7 @@ /// public Vector2 ViewToGlobalPosition(Vector2 viewPos) { - // 3.5写法 - //return (viewPos - GameCamera.Main.GlobalPosition + (GameConfig.ViewportSize / 2)) * GameConfig.WindowScale - GameCamera.Main.SubPixelPosition; - return (viewPos - (GameCamera.Main.GlobalPosition + GameCamera.Main.Offset) + (ViewportSize / 2)) * PixelScale; + return (viewPos + GameCamera.Main.PixelOffset - (GameCamera.Main.GlobalPosition + GameCamera.Main.Offset) + (ViewportSize / 2)) * PixelScale; } public long StartCoroutine(IEnumerator able) diff --git a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs index 21e4ab7..a253d34 100644 --- a/DungeonShooting_Godot/src/game/activity/role/player/Player.cs +++ b/DungeonShooting_Godot/src/game/activity/role/player/Player.cs @@ -346,7 +346,7 @@ { _rollCoolingTimer = RoleState.RollTime; } - + // protected override void DebugDraw() // { // base.DebugDraw(); diff --git a/DungeonShooting_Godot/src/game/camera/GameCamera.cs b/DungeonShooting_Godot/src/game/camera/GameCamera.cs index a4a851d..fd48f9b 100644 --- a/DungeonShooting_Godot/src/game/camera/GameCamera.cs +++ b/DungeonShooting_Godot/src/game/camera/GameCamera.cs @@ -20,7 +20,7 @@ DataDelta = dataDelta; } } - + /// /// 当前场景的相机对象 /// @@ -34,9 +34,8 @@ /// /// 恢复系数 /// - [Export] - public float RecoveryCoefficient = 25f; - + [Export] public float RecoveryCoefficient = 25f; + /// /// 抖动开关 /// @@ -46,14 +45,17 @@ /// 镜头跟随鼠标进度 (0 - 1) /// public float FollowsMouseAmount = 0.15f; - + /// /// 相机跟随目标 /// private AdvancedRole _followTarget; - - // 3.5 - //public Vector2 SubPixelPosition { get; private set; } + + /// + /// SubViewportContainer 中的像素偏移, 因为游戏开启了完美像素, SubViewport 节点下的相机运动会造成非常大的抖动, + /// 为了解决这个问题, 在 SubViewport 父节点中对 SubViewport 进行整体偏移, 以抵消相机造成的巨大抖动 + /// + public Vector2 PixelOffset { get; private set; } private long _index = 0; @@ -99,10 +101,9 @@ } var cameraPosition = _camPos; - //var cameraPosition = _camPos + _shakeOffset; var roundPos = cameraPosition.Round(); - var offset = roundPos - cameraPosition; - _offsetShader.SetShaderParameter("offset", offset); + PixelOffset = roundPos - cameraPosition; + _offsetShader.SetShaderParameter("offset", PixelOffset); GlobalPosition = roundPos; Offset = _shakeOffset.Round(); diff --git a/DungeonShooting_Godot/src/game/ui/bottomTips/BottomTipsPanel.cs b/DungeonShooting_Godot/src/game/ui/bottomTips/BottomTipsPanel.cs index a7bba64..495fb5d 100644 --- a/DungeonShooting_Godot/src/game/ui/bottomTips/BottomTipsPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/bottomTips/BottomTipsPanel.cs @@ -69,24 +69,27 @@ yield return 0; //向上移动 - var frame = GameApplication.Instance.TargetFps * _animationTime; - var stepPixel = _movePixel / frame; - for (var i = 0; i < frame; i++) + var time = 0f; + while (time < _animationTime) { - pos.X = L_Panel.Instance.Position.X; - pos.Y -= stepPixel; - L_Panel.Instance.Position = pos; + L_Panel.Instance.Position = new Vector2( + pos.X, + pos.Y - Mathf.Lerp(0, _movePixel, Mathf.Min(time / _animationTime, 1)) + ); + time += (float)GetProcessDeltaTime(); yield return 0; } yield return new WaitForSeconds(3.5f); //向下移动 - for (var i = 0; i < frame; i++) + while (time > 0) { - pos.X = L_Panel.Instance.Position.X; - pos.Y += stepPixel; - L_Panel.Instance.Position = pos; + L_Panel.Instance.Position = new Vector2( + pos.X, + pos.Y - Mathf.Lerp(0, _movePixel, Mathf.Max(time / _animationTime, 0)) + ); + time -= (float)GetProcessDeltaTime(); yield return 0; }