> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Throttle

> Throttle

# Throttle

一种仅带 Y 轴的操纵杆的专用版本，专为驾驶游戏设计。

## 属性

`type` - "throttle"

`axisUp` - *string*。控件上部映射到的扳机键。必须为 `"leftTrigger"` 或 `"rightTrigger"`。

`axisDown` - *string*。控件下部映射到的扳机键。必须为 `"leftTrigger"` 或 `"rightTrigger"`。

`relative` - *boolean*，*可选*。控制油门如何计算其值。若为 `true`，值将根据用户的初始触摸位置计算。若为 `false`，值将根据控件的中心点计算。默认为 `true`。

`sticky` - *boolean*，*可选*。控制用户停止触摸控件时的行为。若为 `true`，油门将保持在最后一个值。若为 `false`，将重置为 0。默认为 `false`。

`enabled` - *boolean*，*可选*。默认为 `true`。将控件的可视状态设置为启用/禁用。禁用的控件仍会接收玩家的输入，但*不会*根据输入更改其可视样式。

`visible` - *boolean*，*可选*。默认为 `true`。确定该控件是否显示给玩家进行交互。要在游戏过程中更改此项，请参阅[使用游戏状态更改触控布局](https://devdocs.xbox.com/zh-CN/build/core-features/common/game-streaming/building-touch-layouts/game-streaming-touch-changing-layouts-game-state.md#change_state)。

`styles` - *object*，*可选*。控件视觉表示的自定义。样式表示为每个可样式化状态对应的一个对象。

油门控件可以为以下状态设置样式。

* `default` - 基本样式。
* `activated` - 玩家触摸旋钮且旋钮恰好位于轴上 0 值时应用。
* `activatedDown` - 玩家触摸旋钮并将旋钮移动到油门轴的负（下）部分时应用。
* `activatedUp` - 玩家触摸旋钮并将旋钮移动到油门轴的正（上）部分时应用。
* `idle` - 玩家*未*与控件交互且旋钮也未处于 `sticky` 上部时应用。
* `idleUp` - 玩家*未*与控件交互且旋钮已被移到上部并 `sticky` 被设置为 `true` 时应用。

**每个状态的样式属性**

`opacity` - *number*，*可选*。应用于控件的不透明度。除 `disabled` 外的所有状态默认为 1.0。

[`axisUp`](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-throttle-axis) - *object*，*可选*。指定油门正（上）部分样式的 [`axis`](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-throttle-axis) 对象。

[`axisDown`](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-throttle-axis) - *object*，*可选*。指定油门负（下）部分样式的 [`axis`](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-throttle-axis) 对象。

[`knob`](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-knob) - *object*，*可选*。指定油门旋钮部分样式的 [`knob`](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-knob) 对象。

`indicator` - *object*，*可选*。一个 [stroke](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-stroke.md)，指定连接旋钮到轴上当前位置的组件的样式。

**资源尺寸**

对于接受图像资源的每个样式对象，给定的资源以基础分辨率提供，并以该基础分辨率的 1.5x、2.0x、3.0x 和 4.0x 缩放提供。给定图像的分辨率必须小于或等于以下最大分辨率。

| 对象 | @1.0x | @1.5x | @2.0x | @3.0x | @4.0x |
| :- | :- | :- | :- | :- | :- |
| knob.faceImage | 60x60 | 90x90 | 120x120 | 180x180 | 240x240 |
| knob.background | 60x60 | 90x90 | 120x120 | 180x180 | 240x240 |

## 备注

`throttle` 控件允许玩家通过触摸控件提供扳机键的可变压力。

`throttle` 控件设计为放在方向盘的中心位置—并且是该位置与屏幕边缘之间唯一的控件。

如果玩家可能希望对扳机键施加恒定压力以设置该值，然后用手指进行不同操作，请将 `sticky` 设置为 true。

**样式备注**

> [!WARNING]
>
> 通过 Windows 版本的内容测试应用程序进行串流时，并非所有样式都会正确显示。

## 示例

#### 示例 1：基本油门

**图 1. 油门控件**

![用户与油门交互](https://mintcdn.com/microsoft-4404708b/gzrdvT5kpqAXKEQt/images/gdk/reference/game-streaming-touch-control-images-throttle.gif?s=effd39103fb6dd47dbe5275bdfc07426)

这使用默认样式。

```JSON theme={null}
{
    "type": "throttle",
    "axisUp": "rightTrigger",
    "axisDown": "leftTrigger",
    "sticky": true
}
```

#### 示例 2：具有样式化轮廓和显式定义图标的油门

**图 1. 自定义油门控件**

![用户与自定义油门交互](https://mintcdn.com/microsoft-4404708b/gzrdvT5kpqAXKEQt/images/gdk/reference/game-streaming-touch-control-images-throttle-customized.gif?s=bfccc19c022aed00a4e3e14833ab2202)

```JSON theme={null}
{
    "type": "throttle",
    "axisUp": "rightTrigger",
    "axisDown": "leftTrigger",
    "sticky": true,
    "styles": {
        "default": {
            "knob" : {
                "faceImage" : {
                    "type": "icon",
                    "value": "gasPedal"
                }
            },
            "axisUp": {
                "stroke" : {
                    "type": "solid",
                    "color":  "#107C10"
                },
                "cap" : {
                    "type": "color",
                    "value": "#107C10"
                }
            },
            "axisDown": {
                "stroke" : {
                    "type": "solid",
                    "color":  "#ff0000"
                },
                "cap" : {
                    "type": "color",
                    "value": "#ff0000"
                }
            }
        },
        "idleUp" : {
            "knob" : {
                "stroke" : {
                    "type": "solid",
                    "color":  "#107C10"
                }
            },
            "indicator" : {
                "type": "solid",
                "color":  "#107C10"
            }
        },
        "activatedUp" : {
            "indicator" : {
                "type": "solid",
                "color":  "#107C10"
            }
        },
        "activatedDown": {
            "knob" : {
                "faceImage" : {
                    "type": "icon",
                    "value": "brakePedal"
                }
            },
            "indicator" : {
                "type": "solid",
                "color":  "#ff0000"
            }
        }
    }
}
```

## 要求

**布局版本：** 1.0+（样式功能自布局版本 3.2+ 起可用）


## Related topics

- [ThrottleAxis](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-throttle-axis.md)
- [DELETE /titles/{titleId}/users/{xuid}/activities](https://devdocs.xbox.com/zh-CN/reference/live/rest/uri/multiplayeractivity/swagger-uris/uri-DeleteActivity.md)
- [POST /titles/{titleId}/activities/query](https://devdocs.xbox.com/zh-CN/reference/live/rest/uri/multiplayeractivity/swagger-uris/uri-ExternalGetActivityBatch.md)
- [GET /titles/{titleId}/users/{xuid}/activities API](https://devdocs.xbox.com/zh-CN/reference/live/rest/uri/multiplayeractivity/swagger-uris/uri-GetActivity.md)
- [POST /titles/{titleId}/recentplayergroups/server](https://devdocs.xbox.com/zh-CN/reference/live/rest/uri/multiplayeractivity/swagger-uris/uri-PostServerRecentPlayerGroup.md)
