From dea95e0468e8edbb49406539a62329fbc502eb4d Mon Sep 17 00:00:00 2001 From: "petrak@" Date: Sat, 22 Jul 2023 12:06:53 -0500 Subject: [PATCH] Fix resizing the window breaking things: see #131 This PR fixes #130. It has exactly the same fix as PR #131, but doesn't include other changes to the json files and such. @dudecon: pro tip! Learn how to `git rebase`. It lets you re-write history, only allow certain parts of commits, etc... Also thanks for the code for the fix -- I would have no idea how to do that. You're the MVP here. --- Chess-Challenge/src/Framework/Application/Core/Program.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Chess-Challenge/src/Framework/Application/Core/Program.cs b/Chess-Challenge/src/Framework/Application/Core/Program.cs index 378dedf..134db76 100644 --- a/Chess-Challenge/src/Framework/Application/Core/Program.cs +++ b/Chess-Challenge/src/Framework/Application/Core/Program.cs @@ -27,7 +27,7 @@ namespace ChessChallenge.Application Raylib.InitWindow(screenWidth, screenHeight, "Chess Coding Challenge"); Raylib.SetTargetFPS(60); - UpdateCamera(); + UpdateCamera(screenWidth, screenHeight); ChallengeController controller = new(); @@ -56,17 +56,15 @@ namespace ChessChallenge.Application public static void SetWindowSize(Vector2 size) { Raylib.SetWindowSize((int)size.X, (int)size.Y); - UpdateCamera(); + UpdateCamera((int)size.X, (int)size.Y); SaveWindowSize(); } public static Vector2 ScreenToWorldPos(Vector2 screenPos) => Raylib.GetScreenToWorld2D(screenPos, cam); - static void UpdateCamera() + static void UpdateCamera(int screenWidth, int screenHeight) { cam = new Camera2D(); - int screenWidth = Raylib.GetScreenWidth(); - int screenHeight = Raylib.GetScreenHeight(); cam.target = new Vector2(0, 15); cam.offset = new Vector2(screenWidth / 2f, screenHeight / 2f); cam.zoom = screenWidth / 1280f * 0.7f;