Skip to content

Commit

Permalink
QoL change, No More Manually Zooming In For Your Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
loglot authored Aug 31, 2023
1 parent e8c4f3f commit c9fdebd
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
const ctx = canvas.getContext("2d");

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

const originalWidth = canvas.width;
const originalHeight = canvas.height;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
window.requestAnimationFrame(gameLoop)

Expand All @@ -28,7 +29,31 @@
while(true) {
keyManager.doActionsFromKeyInput();
keyManager.onTick();
resizeCanvasForWindowSize()
draw.Game()
await misc.sleep(1000/60)
}
}

function resizeCanvasForWindowSize() {

// Get the current window dimensions
const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight;

// Calculate the desired width and height based on the window's dimensions
const desiredWidth = windowWidth;
const aspectRatio = originalWidth / originalHeight;
const desiredHeight = desiredWidth / aspectRatio;

// Set the canvas element's width and height
canvas.width = desiredWidth;
canvas.height = desiredHeight;

// Resize the canvas drawing area to maintain the aspect ratio
scaleX = (desiredWidth / originalWidth);
scaleY = (desiredHeight / originalHeight);

// Apply the scaling transformation to maintain the aspect ratio
ctx.setTransform(scaleY, 0, 0, scaleX, 0, 0)
}

0 comments on commit c9fdebd

Please sign in to comment.