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
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?

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.