garethquirke

Phaser scale issues when browser window resizes

Recommended Posts

My game does not scale correctly when the browser loads the game while the window size is made smaller.

 

Another scenario is while in game state, the game will resize correctly, If I try to make the window bigger once again the game will be made out of scale and not usable really.

 

this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;

 

Share this post


Link to post
Share on other sites
bootGame.prototype.create = function(){
	console.log("Booting game");

	  if (game.device.desktop) {
        game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
        game.scale.setMinMax(480,320,720,480)
        game.scale.pageAlignHorizontally = true;
        game.scale.pageAlignVertically = true;
    }
    else {
        game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
        game.scale.setMinMax(480,320);
        game.scale.pageAlignHorizontally = true;
        game.scale.pageAlignVertically = true;
        game.scale.forceOrientation(true,false);
    }
    game.scale.refresh();

	game.stage.backgroundColor = "#007f5f";
 

}

The above piece of code should work - best to put it in boot state. Modify scale min max to adjust your game needs - in the example above I say - the game should be scaled to a minimum of 480x320 but if more space it's available scale it to max 720x480. It also places the game nicely in the center. And finally forceOrientation(true,false) sets the game in landscape mode when on mobile (if you want it in portrait mode use forceOrientation(false,true)  )

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.