# Dynamically change canvas size

**URL:** <https://phaser.discourse.group/t/dynamically-change-canvas-size/4213>\
**Category:** Phaser 3\
**Created:** [November 10, 2019, 2:31pm UTC](https://phaser.discourse.group/t/dynamically-change-canvas-size/4213 "2019-11-10T14:31:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreaded\_glove](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dreaded\_glove](https://phaser.discourse.group/u/dreaded_glove)\
**Post date:** [November 10, 2019, 2:31pm UTC](https://phaser.discourse.group/t/dynamically-change-canvas-size/4213/1 "2019-11-10T14:31:54Z")

</div>

I’ve been going crazy trying to figure out how to do this. Something that I feel should be incredibly simple.  
Basically, my canvas always stays the same size when the window size changes:

https://i.imgur.com/81lIQcG.gifv?twitter#t

I need it to resize like in this example:

https://i.imgur.com/aT5ln1k.gifv?twitter#t

The thing is, I can’t find anything in the code of that example that has anything to do with resizing. It’s a complete mystery to me. ([https://labs.phaser.io/view.html?src=src\scalemanager\fit%20hi-res.js&v=3.20.1](https://labs.phaser.io/view.html?src=src%5Cscalemanager%5Cfit%20hi-res.js&v=3.20.1))  
I realize I could check the size in update() but that sounds incredibly expensive, and It’s bvious that in the example the resizing follows at a slower interval, so there is definity some more advanced mechanism at play.

How does it work?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [November 10, 2019, 4:25pm UTC](https://phaser.discourse.group/t/dynamically-change-canvas-size/4213/2 "2019-11-10T16:25:02Z")

</div>

See game config in [https://labs.phaser.io/edit.html?src=src\scalemanager\fit.js](https://labs.phaser.io/edit.html?src=src%5Cscalemanager%5Cfit.js) .

---

<div class="post-metadata">

**Author:** ![dreaded\_glove](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dreaded\_glove](https://phaser.discourse.group/u/dreaded_glove)\
**Post date:** [November 10, 2019, 8:08pm UTC](https://phaser.discourse.group/t/dynamically-change-canvas-size/4213/3 "2019-11-10T20:08:50Z")

</div>

For some reason I had the idea in my mind that scale manager modes had nothing to do with canvas size but just game scale. What I needed was the canvas to fit the window without rescaling my game, so  
`mode: Phaser.Scale.RESIZE` was the right option.

But this is where I run into the next issue. I use `zoom: 4` for my game because it uses pixel art assets, and if I use RESIZE mode the zoom option gets ignored.  
Is there a proper way to combine these two or is there a better strategy for displaying scaled up assets instead of zoom?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [November 11, 2019, 1:22am UTC](https://phaser.discourse.group/t/dynamically-change-canvas-size/4213/4 "2019-11-11T01:22:03Z")

</div>

[Manually resize game with zoom](https://codepen.io/samme/pen/abbjBmy)

---

<div class="post-metadata">

**Author:** ![dreaded\_glove](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@dreaded\_glove](https://phaser.discourse.group/u/dreaded_glove)\
**Post date:** [November 11, 2019, 11:26am UTC](https://phaser.discourse.group/t/dynamically-change-canvas-size/4213/5 "2019-11-11T11:26:07Z")

</div>

Ok thanks! So the current solution is to set the zoom mode to NONE and then resize the window in the resize event.

```
{
    mode: Phaser.Scale.NONE,
    width: window.innerWidth/ZOOM_LEVEL,
    height: window.innerHeight/ZOOM_LEVEL,
    zoom: ZOOM_LEVEL
}

window.addEventListener("resize", () => {
        game.scale.resize(window.innerWidth/ZOOM_LEVEL, window.innerHeight/ZOOM_LEVEL);
    },false
);

```

This works, but it still feels like a workaround for the fact that RESIZE mode and zoom simply don’t work together. Is it fair enough to call that a bug?  
(I’ll mark the first reply as the answer since it answers the actual question in the title)
