简体   繁体   中英

How can I keep the canvas in focus (center) of the camera when the screen size of the browser changes while using Babylonjs?

The user can change the screen size and this distorts the size of the canvas we created and thus the image focus of the camera. To solve this problem, we need to write focusing code.

  relocateCamera_CanvasSize = () => {
        this.engine = this.scene.getEngine();
        this.engine.onResizeObservable.add(() => {
            if (this.scene.getEngine().getRenderHeight() > this.scene.getEngine().getRenderWidth()) {
                camera.fovMode = Camera.FOVMODE_HORIZONTAL_FIXED;
            }
            else {
                camera.fovMode = Camera.FOVMODE_VERTICAL_FIXED;
            }
        });
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM