@@ -23,7 +23,6 @@ export class SceneManager {
23
23
this . spawnedSounds = new Set ( ) ;
24
24
25
25
this . renderer = new THREE . WebGLRenderer ( { alpha : true , antialias : true } ) ;
26
- this . renderer . setPixelRatio ( window . devicePixelRatio ) ;
27
26
this . camera = new THREE . PerspectiveCamera ( ) ;
28
27
this . camera . fov = 55 ;
29
28
this . camera . far = this . camera . position . z = 1000 ;
@@ -72,7 +71,7 @@ export class SceneManager {
72
71
requestAnimationFrame ( this . animate . bind ( this ) ) ;
73
72
74
73
const delta = this . clock . getDelta ( ) ;
75
- this . syncRendererSize ( ) ;
74
+ this . resizeRendererToDisplaySize ( ) ;
76
75
this . moveGridsInfinitely ( delta ) ;
77
76
this . moveTitleUntilRest ( delta ) ;
78
77
this . moveSpawnedModels ( delta ) ;
@@ -189,15 +188,19 @@ export class SceneManager {
189
188
190
189
/**
191
190
* Sync the renderer size with the current canvas size.
191
+ *
192
+ * @see https://threejs.org/manual/en/responsive.html
192
193
*/
193
- private syncRendererSize ( ) : void {
194
+ private resizeRendererToDisplaySize ( ) : void {
194
195
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 ;
197
200
198
- if ( canvas . width !== width || canvas . height !== height ) {
201
+ if ( needResize ) {
199
202
this . renderer . setSize ( width , height , false ) ;
200
- this . camera . aspect = width / height ;
203
+ this . camera . aspect = canvas . clientWidth / canvas . clientHeight ;
201
204
this . camera . updateProjectionMatrix ( ) ;
202
205
}
203
206
}
0 commit comments