handling window resize events
This commit is contained in:
parent
8f536b0242
commit
03687402c9
|
@ -128,6 +128,7 @@ body {
|
||||||
.footer canvas {
|
.footer canvas {
|
||||||
grid-row: 1/2;
|
grid-row: 1/2;
|
||||||
grid-column: 1/2;
|
grid-column: 1/2;
|
||||||
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* grid top */
|
/* grid top */
|
||||||
|
|
|
@ -11,7 +11,9 @@ export const scene = ({ ref }) => {
|
||||||
let nextShip = shipInterval;
|
let nextShip = shipInterval;
|
||||||
|
|
||||||
var scene = new THREE.Scene();
|
var scene = new THREE.Scene();
|
||||||
|
|
||||||
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
||||||
|
|
||||||
const width = ref.current.clientWidth;
|
const width = ref.current.clientWidth;
|
||||||
const height = ref.current.clientHeight;
|
const height = ref.current.clientHeight;
|
||||||
renderer.setSize(width, height);
|
renderer.setSize(width, height);
|
||||||
|
@ -72,7 +74,15 @@ export const scene = ({ ref }) => {
|
||||||
|
|
||||||
ships = ships.filter((s) => !s.kill);
|
ships = ships.filter((s) => !s.kill);
|
||||||
|
|
||||||
|
window.addEventListener('resize', onWindowResize, false);
|
||||||
|
|
||||||
|
function onWindowResize() {
|
||||||
|
camera.updateProjectionMatrix();
|
||||||
|
renderer.setSize(ref.current.clientWidth, ref.current.clientHeight);
|
||||||
|
}
|
||||||
|
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user