GamepadService

Mostrar obsoleto

*Este conteúdo estará disponível no idioma selecionado em breve.

Não criável
Serviço
Não replicado

The GamepadService is internally responsible for handling inputs from various controllers, such as Xbox One or PlayStation DualShock controllers. It also handles APIs used with the gamepad virtual cursor. You can enable the gamepad cursor for your experience by setting Enum.VirtualCursorMode under StarterGui to Enabled.

Resumo

Propriedades

Métodos

Propriedades

GamepadCursorEnabled

Ler Parallel
Segurança do script Roblox

This boolean is a read only variable that maintains the state of the gamepad virtual cursor.

Amostras de código

GamepadService - Gamepad Cursor Enabled Property

local gamepadService = game.GamepadService
gamepadService:GetPropertyChangedSignal("GamepadCursorEnabled"):Connect(function()
local enabled = gamepadService.GamepadCursorEnabled
if enabled then
-- Custom code when the virtual cursor is enabled
else
-- Custom code when the virtual cursor is disabled
end
end)

Métodos

DisableGamepadCursor

void

This function disables the gamepad cursor, if it's currently enabled.


Devolução

void

Amostras de código

GamepadService - Disable Gamepad Cursor

local gamepadService = game.GamepadService
local userInputService = game.UserInputService
userInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.ButtonB then
gamepadService:DisableGamepadCursor()
end
end)

EnableGamepadCursor

void

This function enables the gamepad cursor if it's currently disabled. If the cursor is already enabled, calling the API updates the cursor's position. The function accepts a GuiObject parameter, but there are some invalid cases. Please note that in order to set the cursor to the default position, nil must be passed in as a parameter. Providing no argument will result in an error.

Input GuiObjectCursor Starting Position
NilDefault position
Not a GuiObjectCursor does not appear, errors
Not a child of BasePlayerGuiCursor does not appear, errors
GuiObject has Visible 2 set to false or any parent visible set to falseDefault position with warning
Child of ScreenGui 1 with Enabled 1 set to falseDefault position with warning
Child of BillboardGui 4 or SurfaceGuiDefault position with warning
GuiObject outside the viewport (Or, any part of the gui object that is off screen)Default position with warning
Child of ScrollingFrame with clipping set to false: GuiObject outside of scrolling frame (Object child of scrolling frame and not visible on screen)Default position with warning
Child of ScrollingFrame with clipping set to true: GuiObject outside scrolling frame window but inside viewportGuiObject moves into the scrolling frame and starts the cursor centered over the object
GuiObject inside the frame and visibleCursor starts centered on the GuiObject

Parâmetros

guiObject: Instance

Devolução

void

Amostras de código

GamepadService - Enable Gamepad Cursor

local gamepadService = game.GamepadService
local userInputService = game.UserInputService
local startObject = script.Parent
userInputService.InputBegan:Connect(function(inputObject, gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.ButtonA then
gamepadService:EnableGamepadCursor(startObject)
end
end)

Eventos