fix camera
This commit is contained in:
parent
abe1e2ca54
commit
344569edee
@ -140,11 +140,7 @@ class GameEngine {
|
||||
}
|
||||
});
|
||||
|
||||
this.canvas.addEventListener('wheel', (e) => {
|
||||
e.preventDefault();
|
||||
const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1;
|
||||
this.renderer.setZoom(this.renderer.camera.zoom * zoomFactor);
|
||||
});
|
||||
// Zoom controls disabled for fixed camera view
|
||||
}
|
||||
|
||||
start() {
|
||||
@ -184,7 +180,6 @@ class GameEngine {
|
||||
if (this.puckActive) {
|
||||
this.puck.update(deltaTime, this.gameState, this.players);
|
||||
this.updateCollisions();
|
||||
this.renderer.updateCamera(this.puck.position);
|
||||
}
|
||||
|
||||
this.updateEffects(deltaTime);
|
||||
|
||||
@ -2,15 +2,9 @@ class Renderer {
|
||||
constructor(canvas) {
|
||||
this.canvas = canvas;
|
||||
this.ctx = canvas.getContext('2d');
|
||||
this.camera = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
zoom: 1,
|
||||
target: null,
|
||||
smoothing: 0.1
|
||||
};
|
||||
|
||||
this.setupCanvas();
|
||||
this.setupFixedCamera();
|
||||
}
|
||||
|
||||
setupCanvas() {
|
||||
@ -18,6 +12,27 @@ class Renderer {
|
||||
this.ctx.imageSmoothingEnabled = false;
|
||||
}
|
||||
|
||||
setupFixedCamera() {
|
||||
const rinkWidth = 1000;
|
||||
const rinkHeight = 600;
|
||||
const padding = 50;
|
||||
|
||||
const scaleX = this.canvas.width / (rinkWidth + padding * 2);
|
||||
const scaleY = this.canvas.height / (rinkHeight + padding * 2);
|
||||
const zoom = Math.min(scaleX, scaleY);
|
||||
|
||||
const x = (this.canvas.width - rinkWidth * zoom) / 2;
|
||||
const y = (this.canvas.height - rinkHeight * zoom) / 2;
|
||||
|
||||
this.camera = {
|
||||
x: x,
|
||||
y: y,
|
||||
zoom: zoom,
|
||||
target: null,
|
||||
smoothing: 0.1
|
||||
};
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
}
|
||||
@ -242,17 +257,7 @@ class Renderer {
|
||||
}
|
||||
|
||||
updateCamera(target) {
|
||||
if (target) {
|
||||
this.camera.target = target;
|
||||
}
|
||||
|
||||
if (this.camera.target) {
|
||||
const targetX = this.canvas.width / 2 - this.camera.target.x * this.camera.zoom;
|
||||
const targetY = this.canvas.height / 2 - this.camera.target.y * this.camera.zoom;
|
||||
|
||||
this.camera.x += (targetX - this.camera.x) * this.camera.smoothing;
|
||||
this.camera.y += (targetY - this.camera.y) * this.camera.smoothing;
|
||||
}
|
||||
// Camera is now fixed - no updates needed
|
||||
}
|
||||
|
||||
applyCamera() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user