Problem at orientation change


I’m trying to implement portrait and landscape mode for my game.
At boot state I have:

this.scale.scaleMode = Phaser.ScaleManager.RESIZE;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;

In index.html I have:

$(window).on("orientationchange", function (event) {

function resizeGame() {
var height = $(window).height();
var width = $(window).width(); = width; = height; = width; = height;
if ( === Phaser.WEBGL) {, height);

I init game this way: = new Phaser.Game($(window).width(), $(window).height(), Phaser.AUTO, 'canvasContainer', null, false, true);

When I turn phone from portrait mode to landscape, there is black blackground at the right. As it is seen in second image yellow goal sprite is on top of black background. It seems that tilemap didn’t refresh. Why this is happening?


Hi @microspace,
You need to resize your tilemap layer in the function resizeGame() with the method resize(width, height).
This is an official phaser example modified for this case:

See the Pen [Phaser CE] Resize tilemap by Juan Jose Capellan (@jjcapellan) on CodePen.



I found it normal to have spaces when I resize a game in canvas, so it’s important to center the canvas
I mostly use


The RESIZE scale mode will create a Canvas element for your game that is the same size as the
parent container.


Also, use game.scale.setGameSize() instead.


Thank you very much! Totally helpful answer! Also I need to resize each layer of Tilemap.
And I replaced setResizeCallback to onSizeChange.