Jump to content

Detect desktop before game initialisation


Yanifska
 Share

Recommended Posts

I am not sure I follow...I am testing on desktop ( chrome, IE, firefox) and I get a false result where I expect true, so the game could be set at a specific size.

The game is working (kind of)  fine on mobile devices. My trouble is how to detect when I am on desktop, before initialising the game.

I thought it was something basic....

Thank you anyway

Link to comment
Share on other sites

Hi, 

 

if you are using only one state in your app, try this in the create function:

 

if(this.game.device.desktop) {
 
// desktop view - desktop code here
this.scale.pageAlignHorizontally = true;
//this.scale.setScreenSize(true);
 
} else {
 
// game sacle: min: 480X260, max: 1026X768 - non-desktop code here
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.minWidth = 568;
this.scale.minHeight = 600;
this.scale.maxWidth = 2048;
this.scale.maxHeight = 1536;
this.scale.forceLandscape = true;
this.scale.pageAlignHorizontally = true;
this.scale.setScreenSize(true);
}
 
I'm also assuming that you are using this line as your game object, mainly the "game" variable, as I am using this.game above:
var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, '');
 
I used that line on my very first state of my game, I am using many states in my game to handle the load screen, menu screen, level 1 screen etc.
So I added the above code in my "Boot" state, which runs first than any other state. Also remember that every state can has the same 'perload()', 'create()', and 'update()' functions among others.
 
Let me know if this helps.
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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