Skip to content

Commit 70f5568

Browse files
committed
Factor pixel ratio into resize check
1 parent 8900e8f commit 70f5568

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/lib/scene-manager.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class SceneManager {
2323
this.spawnedSounds = new Set();
2424

2525
this.renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
26-
this.renderer.setPixelRatio(window.devicePixelRatio);
2726
this.camera = new THREE.PerspectiveCamera();
2827
this.camera.fov = 55;
2928
this.camera.far = this.camera.position.z = 1000;
@@ -72,7 +71,7 @@ export class SceneManager {
7271
requestAnimationFrame(this.animate.bind(this));
7372

7473
const delta = this.clock.getDelta();
75-
this.syncRendererSize();
74+
this.resizeRendererToDisplaySize();
7675
this.moveGridsInfinitely(delta);
7776
this.moveTitleUntilRest(delta);
7877
this.moveSpawnedModels(delta);
@@ -189,15 +188,19 @@ export class SceneManager {
189188

190189
/**
191190
* Sync the renderer size with the current canvas size.
191+
*
192+
* @see https://threejs.org/manual/en/responsive.html
192193
*/
193-
private syncRendererSize(): void {
194+
private resizeRendererToDisplaySize(): void {
194195
const canvas = this.renderer.domElement;
195-
const width = canvas.clientWidth;
196-
const height = canvas.clientHeight;
196+
const pixelRatio = window.devicePixelRatio;
197+
const width = Math.floor(canvas.clientWidth * pixelRatio);
198+
const height = Math.floor(canvas.clientHeight * pixelRatio);
199+
const needResize = canvas.width !== width || canvas.height !== height;
197200

198-
if (canvas.width !== width || canvas.height !== height) {
201+
if (needResize) {
199202
this.renderer.setSize(width, height, false);
200-
this.camera.aspect = width / height;
203+
this.camera.aspect = canvas.clientWidth / canvas.clientHeight;
201204
this.camera.updateProjectionMatrix();
202205
}
203206
}

0 commit comments

Comments
 (0)