I’m trying to prevent this:
On phones I’d like to move this button up a bit and make it smaller. On PC, I want to leave it where it is.
I’ve searching around a bit and I can’t find the definitive way to check if my player is running on a phone or not. There’s a bunch of hacks from 2016. How do I do it today?
May 6, 2020, 9:26pm
Most solutions will probably be to check
UserInputService.TouchEnabled and also ensure that there’s no mouse. That pretty much guarantees the existence of the jump button, and therefore lets you reposition accordingly.
May 6, 2020, 9:28pm
TouchEnabled might be the way to go in this, and perhaps think about checking if there is no mouse button being clicked, by a “if not” statement?
You might also want to make sure
GamepadEnabled is false so that controller users don’t get registered as having touch screens.
Edit: For clarity, I mean using a console controller with a touch-screen laptop.
This was a good explanation of the best way to handle this from a post a few years ago; you should still handle it the same way today.
Bad idea, this can also return true for laptops/PCs with touch-enabled screens.
In general, you shouldn’t write code for specific platforms. You should write code that is able to adapt to varying screen sizes and varying input modes.
If you have to know if something is a mobile device (i.e. primary Touch as input mode), use this check instead, it is more robust:
local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
if UIS.TouchEnabled and not UIS.Ke…
No… that’s the exact opposite of what you should be doing. Let’s try this explanation again more thoroughly.
You really do not write control/UI code for a particular device. The Xbox One has controller as its main input type, so what you’re really wanting to do is implement your game to work with the controller input modes, and that your game will adjust the UI labels and size of the UI appropriately when it detects the last input type is controller / the player is playing on a 10-ft screen (th…
Yeah I found that thread and found it unsatisfactory.
I just want to fix my UI for phones. I don’t want to get drawn into an ideological fight about whether I should write platform specific code or not.
Writing a GUI that looks good at all resolutions is too hard. I want to do two - Small and Large. Websites do this all the time. It’s normal.
He’s not saying you shouldn’t have device specific UI, he’s saying you should change it dynamically based on the last input rather than trying to figure out the device they’re on.
This makes sure that it will function on all devices properly as there’s no surefire way to check the specific device type.
February 15, 2021, 1:58am
Use this to check if the player has touch controls.
Sorry for bumping.
local touchGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):FindFirstChild("TouchGui")
if touchGui then
--has touch controls
--doesn't have touch controls