Yanifska

Detect desktop before game initialisation

Recommended Posts

Hi,

I am trying to use the following line - before game initialization -  to detect if the game will be running on desktop and set a specific size.

 if(Phaser.Device.desktop)

This return always false.

Please show me the right way.

Thank you

Yaniv

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

corpsefilth, I am using the mobile template

currently I have a code close to what you provided in my boot.js

so I guess it is the right way to do it

Somehow I thought it was better to check and set the size before the game initialisation.

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.