Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update backup #16

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
const ctx = canvas.getContext("2d");

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

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

Expand All @@ -28,7 +31,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)
}