From 34c58dcd71ba86f5a5efbe65cec68242bf056f69 Mon Sep 17 00:00:00 2001 From: Zutatensuppe Date: Sat, 17 Apr 2021 19:11:43 +0200 Subject: [PATCH] remove canvas requirement for camera --- game/Camera.js | 21 ++------------------- game/game.js | 6 +++--- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/game/Camera.js b/game/Camera.js index 9338986..c9e2cb4 100644 --- a/game/Camera.js +++ b/game/Camera.js @@ -1,28 +1,14 @@ export default class Camera { - constructor(canvas) { + constructor() { this.x = 0 this.y = 0 - // TODO: when canvas resizes, this should - // syncronize with the cam - this.width = canvas.width - this.height = canvas.height - this.zoom = 1 this.minZoom = .1 this.maxZoom = 6 this.zoomStep = .05 } - rect() { - return { - x: -this.x, - y: -this.y, - w: this.width / this.zoom, - h: this.height / this.zoom, - } - } - move(x, y) { this.x += x / this.zoom this.y += y / this.zoom @@ -34,10 +20,7 @@ export default class Camera { return false } - const zoomToCoord = viewportCoordCenter || { - x: this.width / 2, - y: this.height / 2 - } + const zoomToCoord = viewportCoordCenter const zoomFactor = (1 / this.zoom) - (1 / zoom) this.x -= Math.round(zoomToCoord.x * zoomFactor) diff --git a/game/game.js b/game/game.js index fe4ad60..68d1183 100644 --- a/game/game.js +++ b/game/game.js @@ -408,11 +408,11 @@ async function main() { // initialize some view data // this global data will change according to input events - const viewport = new Camera(canvas) + const viewport = new Camera() // center viewport viewport.move( - -(TABLE_WIDTH - viewport.width) /2, - -(TABLE_HEIGHT - viewport.height) /2 + -(TABLE_WIDTH - canvas.width) /2, + -(TABLE_HEIGHT - canvas.height) /2 ) const playerBgColor = () => {