pixi-viewport icon indicating copy to clipboard operation
pixi-viewport copied to clipboard

Resize the pixi-viewport on window resize events

Open ben4d85 opened this issue 4 years ago • 1 comments

I am trying to get the pixi-viewport to resize automatically following a window resize event.

The problem is that after resizing, the user needs to drag on the page for the viewport to get updated. I would like this to happen automatically instead.

// Listen for window resize events
window.addEventListener('resize', this.onResize);

// Resize handler
onResize = () => {

    // Resize the pixi app's renderer
    this.pixiApp.renderer.resize(
        window.innerWidth,
        window.innerHeight
    );

    // Resize the pixi viewport
    this.pixiViewport.resize(
        window.innerWidth,
        window.innerHeight,
        this.pixiViewport.worldWidth,
        this.pixiViewport.worldHeight,
    );

    // Update the pixi viewport
    this.pixiViewport.update();
}

ben4d85 avatar Sep 17 '21 11:09 ben4d85

You shouldn't need the viewport.update() command. The viewport.resize() command should resize and on the next draw everything should be correct. Seeing as you're using pixi.application that should happen on every frame. Check that the resize is being called properly after an event.

davidfig avatar Sep 17 '21 13:09 davidfig