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.height = wrapperHeight + "px";
this.canvasDebug.width = this.canvas.width;
this.canvasDebug.height = this.canvas.height;
if (this.canvasDebug.width !== this.canvas.width || this.canvasDebug.height !== this.canvas.height) {
this.canvasDebug.width = this.canvas.width;
this.canvasDebug.height = this.canvas.height;
}
// Reinitialize gui
this.minecraft.screenRenderer.initialize();
@@ -389,6 +391,7 @@ export default class GameWindow {
// Render first frame
if (this.minecraft.isInGame()) {
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 {
static VERSION = "1.1.3"
static VERSION = "1.1.4"
static URL_GITHUB = "https://github.com/labystudio/js-minecraft";
static PROTOCOL_VERSION = 758;
@@ -3,16 +3,14 @@ export default class ScreenRenderer {
constructor(minecraft, window) {
this.minecraft = minecraft;
this.window = window;
this.upscale = window.isMobileDevice() ? 1 : 4;
}
initialize() {
this.resolution = this.minecraft.isInGame() ? 1 : this.minecraft.window.scaleFactor; // Increase resolution for the splash text
let scale = this.getLimitedScaleFactor();
// Update camera size
this.window.canvas.width = this.window.width * this.upscale;
this.window.canvas.height = this.window.height * this.upscale;
this.window.canvas.width = this.window.width * scale;
this.window.canvas.height = this.window.height * scale;
// Get context stack of 2d canvas
this.stack2d = this.window.canvas.getContext('2d');
@@ -22,6 +20,8 @@ export default class ScreenRenderer {
}
render(partialTicks) {
let scale = this.getLimitedScaleFactor();
let mouseX = this.minecraft.window.mouseX;
let mouseY = this.minecraft.window.mouseY;
@@ -29,13 +29,13 @@ export default class ScreenRenderer {
// Draw world to canvas
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 {
this.reset();
}
// Scale GUI
this.stack2d.scale(this.upscale, this.upscale, this.upscale);
this.stack2d.scale(scale, scale, scale);
try {
// Render in-game overlay
@@ -52,7 +52,8 @@ export default class ScreenRenderer {
}
// 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
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);
}
getLimitedScaleFactor() {
return Math.min(this.window.scaleFactor, 4);
}
}