object.number

类型 数字
对象 InputAxis
修订版本 版本 2024.3703
关键词 设备,输入,轴,数字

概述

分配给输入设备轴的数字。此数字基于在一个输入设备上找到的轴数。例如,如果一个输入设备有 4 个轴,那么它们将按照找到的顺序被分配数字 1234。您可以使用此数字来唯一标识属于一个输入设备的轴。此轴号可以用作其输入设备的 getAxes() 函数返回的数组的索引。

注意事项

此轴号是识别属于一个输入设备的轴的唯一可靠方法。这是因为它有可能轴 类型 属性返回重复的类型名称,尤其是在类型为 "unknown" 时更是如此。这也因为 类型 名称并不总是与设备上实际按下的内容匹配(尤其适用于为其他平台设计的游戏手柄和操纵杆)。如果您需要向用户显示轴名称,则应显示此轴号而不是 类型 属性。

示例

-- Fetch all input devices currently connected to the system
local inputDevices = system.getInputDevices()

-- Traverse all input devices
for deviceIndex = 1,#inputDevices do
    -- Fetch the input device's axes
    local inputAxes = inputDevices[deviceIndex]:getAxes()

    -- Print all axis numbers
    for axisIndex = 1,#inputAxes do
        local inputAxis = inputAxes[axisIndex]
        print( inputAxis.descriptor .. ": Axis number = " .. tostring(inputAxis.number) )
    end
end