GamepadService

显示已弃用

*该内容即将支持你的所选语言。

无法创建
服务
未复制

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.

概要

方法

属性

GamepadCursorEnabled

读取并联
Roblox 脚本安全性

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

代码示例

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)

方法

DisableGamepadCursor

void

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


返回

void

代码示例

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

参数

guiObject: Instance

返回

void

代码示例

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)

活动