Check if mobile

Is there any way in Phaser 3 to check if the current device is desktop or mobile (or similar)? I think this was available in Phaser 2 but I can’t seem to find anything for v3.

1 Like

You can use the device property on your Game instance to access the device configuration, similarly to Phaser 2.

1 Like

Hey I’ve written a blog post explaining it in detail: How to Check if a Player is on Mobile or Desktop

Checking for the device / user agent can be unreliable at times. Actually, even Phaser has to guess what the player’s device is because currently there isn’t a conform way to check that across all browsers & OS & devices. That’s why usually it’s much more reliable to check for touch input instead of trying to guess the user’s device.

Anyways, I’ve described both methods in my blog post if you’re interested.

3 Likes

Thanks, I will check it out!

@Telinc1 - for some reason this did not work for me so I ended up checking the user agent instead.

if (this.sys.game.device.os.desktop){
            console.log("desktop")
}
else{
           console.log("mobile")
}
6 Likes