Jump to content

Phaser scale issues when browser window resizes


garethquirke
 Share

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;

 

Link to comment
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)  )

Link to comment
Share on other sites

  • 2 years later...
On 4/21/2017 at 12:42 AM, samme said:

I'm following a course, using CE version 2.10. I used it on a prior project (same version) in which 

init: function() {
 
game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
game.scale.pageAlignHorizontally = true;
game.scale.pageAlignVertically = true;
},

worked perfectly to align and scale the background, but for some reason that same code is not working on the new project. We're referring to the phaser.min.js in a script section at the bottom of the index.html file as before.

I'm literally stuck. I know I can use coordinates, but that is a pain in the butt. It seems to be roughly scaling, but with the background image definitely not centered either horizontally or vertically.

I'm editing with Visual Studio Code version 1.34 stable. BTW, can you suggest a nice bracket coloring extension that works nicely with Phaser?

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...