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.
This commit is contained in:
parent
385851a329
commit
dea95e0468
1 changed files with 3 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue