Window on resize, and aspect ratio

Here is another one:
I wanted to handle window resizing,

window.addEventListener( 'resize', onWindowResize, false );
function onWindowResize(){
    renderer.setSize( window.innerWidth, window.innerHeight );
}

This “mostly” works, except that the particles color is reset to black, and the aspect ratio is not updated, transforming balls in eggs … and I have no idea how to fix this.

Thanks 🙂

Author: Fantashit

1 thought on “Window on resize, and aspect ratio

  1. You also need to update the camera:

    window.addEventListener( 'resize', onWindowResize, false );
    
    function onWindowResize(){
    
        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
    
        renderer.setSize( window.innerWidth, window.innerHeight );
    
    }

Comments are closed.