fix gui scaling issue, 1.1.4

This commit is contained in:
LabyStudio
2022-06-18 07:13:54 +02:00
parent bd4017efd5
commit 4d8ce1688e
3 changed files with 19 additions and 11 deletions
+5 -2
View File
@@ -375,8 +375,10 @@ export default class GameWindow {
this.canvas.style.width = wrapperWidth + "px"; this.canvas.style.width = wrapperWidth + "px";
this.canvas.style.height = wrapperHeight + "px"; this.canvas.style.height = wrapperHeight + "px";
this.canvasDebug.width = this.canvas.width; if (this.canvasDebug.width !== this.canvas.width || this.canvasDebug.height !== this.canvas.height) {
this.canvasDebug.height = this.canvas.height; this.canvasDebug.width = this.canvas.width;
this.canvasDebug.height = this.canvas.height;
}
// Reinitialize gui // Reinitialize gui
this.minecraft.screenRenderer.initialize(); this.minecraft.screenRenderer.initialize();
@@ -389,6 +391,7 @@ export default class GameWindow {
// Render first frame // Render first frame
if (this.minecraft.isInGame()) { if (this.minecraft.isInGame()) {
this.minecraft.worldRenderer.render(0); this.minecraft.worldRenderer.render(0);
this.minecraft.onRender(0)
} }
} }
+1 -1
View File
@@ -25,7 +25,7 @@ import FocusStateType from "../util/FocusStateType.js";
export default class Minecraft { export default class Minecraft {
static VERSION = "1.1.3" static VERSION = "1.1.4"
static URL_GITHUB = "https://github.com/labystudio/js-minecraft"; static URL_GITHUB = "https://github.com/labystudio/js-minecraft";
static PROTOCOL_VERSION = 758; static PROTOCOL_VERSION = 758;
@@ -3,16 +3,14 @@ export default class ScreenRenderer {
constructor(minecraft, window) { constructor(minecraft, window) {
this.minecraft = minecraft; this.minecraft = minecraft;
this.window = window; this.window = window;
this.upscale = window.isMobileDevice() ? 1 : 4;
} }
initialize() { initialize() {
this.resolution = this.minecraft.isInGame() ? 1 : this.minecraft.window.scaleFactor; // Increase resolution for the splash text let scale = this.getLimitedScaleFactor();
// Update camera size // Update camera size
this.window.canvas.width = this.window.width * this.upscale; this.window.canvas.width = this.window.width * scale;
this.window.canvas.height = this.window.height * this.upscale; this.window.canvas.height = this.window.height * scale;
// Get context stack of 2d canvas // Get context stack of 2d canvas
this.stack2d = this.window.canvas.getContext('2d'); this.stack2d = this.window.canvas.getContext('2d');
@@ -22,6 +20,8 @@ export default class ScreenRenderer {
} }
render(partialTicks) { render(partialTicks) {
let scale = this.getLimitedScaleFactor();
let mouseX = this.minecraft.window.mouseX; let mouseX = this.minecraft.window.mouseX;
let mouseY = this.minecraft.window.mouseY; let mouseY = this.minecraft.window.mouseY;
@@ -29,13 +29,13 @@ export default class ScreenRenderer {
// Draw world to canvas // Draw world to canvas
if (this.minecraft.isInGame()) { if (this.minecraft.isInGame()) {
this.stack2d.drawImage(this.window.canvasWorld, 0, 0, this.window.width * this.upscale, this.window.height * this.upscale); this.stack2d.drawImage(this.window.canvasWorld, 0, 0, this.window.width * scale, this.window.height * scale);
} else { } else {
this.reset(); this.reset();
} }
// Scale GUI // Scale GUI
this.stack2d.scale(this.upscale, this.upscale, this.upscale); this.stack2d.scale(scale, scale, scale);
try { try {
// Render in-game overlay // Render in-game overlay
@@ -52,7 +52,8 @@ export default class ScreenRenderer {
} }
// Scale GUI back // Scale GUI back
this.stack2d.scale(1 / this.upscale, 1 / this.upscale, 1 / this.upscale); let actualScale = this.window.scaleFactor;
this.stack2d.scale(1 / actualScale, 1 / actualScale, 1 / actualScale);
// Render items // Render items
this.stack2d.drawImage(this.window.canvasItems, 0, 0); this.stack2d.drawImage(this.window.canvasItems, 0, 0);
@@ -64,4 +65,8 @@ export default class ScreenRenderer {
this.stack2d.clearRect(0, 0, this.window.canvas.width, this.window.canvas.height); this.stack2d.clearRect(0, 0, this.window.canvas.width, this.window.canvas.height);
} }
getLimitedScaleFactor() {
return Math.min(this.window.scaleFactor, 4);
}
} }