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)

อีเวนต์