Setting mobile touch button to the same position on all devices?

I’m trying to set the position of a mobile button right next to the jump button, but using scale nor offset works and the button appears in different places on all devices:

contextActionService:SetPosition("testButton",UDim2.new(0,40,0,80))

In the studio emulator:

image

On my phone:

image

1 Like

I have my mobile buttons script wait for the jump button, then copy its position and offset it.

1 Like

How do you do that? The mobile button which is created by contextActionService:BindAction() is in a different frame which also has a custom size and position. Do you somehow re-parent it?

I don’t really understand what you mean, if I remember correctly all you’d have to do is this:

local jumpbutton = game.Players.LocalPlayer.PlayerGui.TouchGui.TouchControlFrame:WaitForChild("JumpButton")
contextActionService:SetPosition("testButton", jumpbutton.Position-UDim2.new(0,80,0,0))
8 Likes

OH, okay! I overthough it, was a simple fix. Thanks :grin:

1 Like

Keep in mind there’s a “big mobile” and “small mobile” layout for mobile devices. Whether one or the other is used is derived from the screen size, check the control scripts for the exact values. Offsetting by (0,80,0,0) will cause the button to overlap with the jump button still on the “big mobile” layout. You’ll probably want to apply a different offset for “big mobile”.

2 Likes