From 3623227ab621edf2ddd624df504f629b6d14e7dc Mon Sep 17 00:00:00 2001 From: w0wca7a Date: Mon, 8 Dec 2025 18:47:24 +0300 Subject: [PATCH 1/4] Add compute shader example --- .../interacting-with-shader.md | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 en/manual/graphics/effects-and-shaders/shading-language/interacting-with-shader.md diff --git a/en/manual/graphics/effects-and-shaders/shading-language/interacting-with-shader.md b/en/manual/graphics/effects-and-shaders/shading-language/interacting-with-shader.md new file mode 100644 index 000000000..23a1261d7 --- /dev/null +++ b/en/manual/graphics/effects-and-shaders/shading-language/interacting-with-shader.md @@ -0,0 +1,127 @@ +# Interacting with the Compute shader + +To use the Compute Shader in Stride, you can inherit [ComputeShaderBase](https://github.com/stride3d/stride/blob/master/sources/engine/Stride.Rendering/Rendering/ComputeEffect/ComputeShaderBase.sdsl) and override the `Compute` method. +``` +// CustomComputeShader.sdsl +CustomComputeShader : ComputeShaderBase +{ + // RWStructuredBuffer - a read/write buffer + stage RWStructuredBuffer ReadWriteBuffer; + override void Compute() + { + // Store data in buffer + ReadWriteBuffer[0] = 1.0f; + } +}; +``` +In some cases, data from the Compute shader can be retrieved back. +For this purpose, [several types of resources](https://learn.microsoft.com/en-us/windows/win32/direct3d11/direct3d-11-advanced-stages-cs-resources) with the `RW` (Read/Write) prefix are used, which allows the shader to simultaneously read and write data. +``` +// SimpleValues.sdsl +shader SimpleValues : ComputeShaderBase +{ + stage float LerpValue; + float ValueA; + float ValueB; + + // RWStructuredBuffer - a read/write buffer + // used to pass the result back to the CPU + stage RWStructuredBuffer ResultBuffer; + + // Main Compute shader function + // Called for each compute thread + override void Compute() + { + // Linear interpolation between ValueA and ValueB + float result = lerp(ValueA, ValueB, LerpValue); + // Write the result to the buffer + // The buffer is 1 element in size, so we use index 0 + ResultBuffer[0] = result; + } +}; +``` + +``` +using Stride.Engine; +using Stride.Graphics; +using Stride.Rendering; +using Stride.Rendering.ComputeEffect; + +public class SimpleValues : SyncScript +{ + private ComputeEffectShader computeEffectShader; + + private readonly float ValueA = 20; + private readonly float ValueB = 2000; + private float LerpValue; // using lerp for example + + // Buffer for calculation result + private Buffer floatBuffer; + + private RenderDrawContext renderDrawContext; + private CommandList commandList; + + public override void Start() + { + // Get base render context from Services + RenderContext renderContext = RenderContext.GetShared(Services); + + commandList = Game.GraphicsContext.CommandList; + + // Compute shader + computeEffectShader = new ComputeEffectShader(renderContext); + + // Draw context needs for PerDraw update data in shader + renderDrawContext = new(Services, renderContext, Game.GraphicsContext); + + // New result Buffer with 1 float type element + // BufferFlags.RawBuffer - random access buffer + // BufferFlags.UnorderedAccess - random access buffer for computations + floatBuffer = Buffer.New(GraphicsDevice, 1, BufferFlags.RawBuffer | BufferFlags.UnorderedAccess); + + computeEffectShader.ShaderSourceName = "SimpleValues"; // the name of *.sdsl file + + // Passing parameters to a shader via keys + computeEffectShader.Parameters.Set(SimpleValuesKeys.ValueA, ValueA); + computeEffectShader.Parameters.Set(SimpleValuesKeys.ValueB, ValueB); + + // Binding the result buffer to the shader + computeEffectShader.Parameters.Set(SimpleValuesKeys.ResultBuffer, floatBuffer); + } + public override void Update() + { + if (LerpValue >= 1) LerpValue = 0f; + LerpValue += 0.001f; + + // Updating the data in the shader + computeEffectShader.Parameters.Set(SimpleValuesKeys.LerpValue, LerpValue); + + // Starting execution of a Ņompute shader on the GPU. + computeEffectShader.Draw(renderDrawContext); + + // Get datas from shader: + + // 1. Value + var lVal = computeEffectShader.Parameters.GetValues(SimpleValuesKeys.LerpValue); + + // 2. Object + var bufObj = computeEffectShader.Parameters.GetObject(SimpleValuesKeys.ResultBuffer); + + // 3. Extracting data from the GPU buffer to CPU memory + // Note: This is a synchronous operation and can be slow for large data sets. + var rVal = (bufObj as Buffer).GetData(commandList); + + DebugText.Print(rVal[0].ToString(), new Stride.Core.Mathematics.Int2(240, 240)); + DebugText.Print(lVal[0].ToString(), new Stride.Core.Mathematics.Int2(240, 260)); + } +} +``` + +## See also + +* [Effect language](../effect-language.md) +* [Shading language index](index.md) + - [Shader classes, mixins, and inheritance](shader-classes-mixins-and-inheritance.md) + - [Composition](composition.md) + - [Templates](templates.md) + - [Shader stage input/output automatic management](automatic-shader-stage-input-output.md) \ No newline at end of file From 3c3ae16c2d6d59d34e49d435d05ca5df8f9e9ca0 Mon Sep 17 00:00:00 2001 From: w0wca7a Date: Tue, 9 Dec 2025 20:36:15 +0300 Subject: [PATCH 2/4] Visual styles --- .../shading-language/interacting-with-shader.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/manual/graphics/effects-and-shaders/shading-language/interacting-with-shader.md b/en/manual/graphics/effects-and-shaders/shading-language/interacting-with-shader.md index 23a1261d7..5d6ccf953 100644 --- a/en/manual/graphics/effects-and-shaders/shading-language/interacting-with-shader.md +++ b/en/manual/graphics/effects-and-shaders/shading-language/interacting-with-shader.md @@ -41,7 +41,7 @@ shader SimpleValues : ComputeShaderBase }; ``` -``` +```csharp using Stride.Engine; using Stride.Graphics; using Stride.Rendering; From d531b16526555d7e21ef186a2e3d7526066a04e9 Mon Sep 17 00:00:00 2001 From: w0wca7a Date: Sun, 8 Feb 2026 21:58:11 +0300 Subject: [PATCH 3/4] Update Scene pages and images --- en/manual/game-studio/create-a-scene.md | 10 +- en/manual/game-studio/manage-scenes.md | 10 +- en/manual/game-studio/media/add-scene.png | 3 - en/manual/game-studio/media/add-scene.webp | 3 + .../media/properties-parent-scene.png | 3 - .../media/settings-key-bindings.png | 3 - .../media/settings-key-bindings.webp | 3 + .../navigate-in-the-scene-editor.md | 2 +- en/manual/input/gamecontrollers.md | 131 ++++++++++++++++++ 9 files changed, 141 insertions(+), 27 deletions(-) delete mode 100644 en/manual/game-studio/media/add-scene.png create mode 100644 en/manual/game-studio/media/add-scene.webp delete mode 100644 en/manual/game-studio/media/properties-parent-scene.png delete mode 100644 en/manual/game-studio/media/settings-key-bindings.png create mode 100644 en/manual/game-studio/media/settings-key-bindings.webp create mode 100644 en/manual/input/gamecontrollers.md diff --git a/en/manual/game-studio/create-a-scene.md b/en/manual/game-studio/create-a-scene.md index 3f9c9b394..e2c08e0aa 100644 --- a/en/manual/game-studio/create-a-scene.md +++ b/en/manual/game-studio/create-a-scene.md @@ -11,15 +11,9 @@ You can create scenes like any other asset. As they are complex assets, they hav 1. In the **Asset View** (by default in the bottom pane), click **Add asset** and select **Scenes**. - ![Add a scene](media/add-scene.png) + ![Add a scene](media/add-scene.webp) -2. Select the appropriate **scene template**. - - Template | Result - ---------|-------- - Empty scene | An empty scene with no entities or preconfigured rendering pipeline - Scene with HDR pipeline | A scene containing basic entities and preconfigured for HDR rendering - Scene with LDR pipeline | A scene containing basic entities and preconfigured for LDR rendering +2. Select the **Scene**. ## Open a scene in the Scene Editor diff --git a/en/manual/game-studio/manage-scenes.md b/en/manual/game-studio/manage-scenes.md index 5e3d8a1ff..aad73c902 100644 --- a/en/manual/game-studio/manage-scenes.md +++ b/en/manual/game-studio/manage-scenes.md @@ -21,15 +21,7 @@ Scenes are kept in different folders. This means that different people can work The relationship between parent and child scenes is set on the child, not the parent. In other words, child scenes know about their parent scenes, but parent scenes don't know about their child scenes. -There are several ways to make a scene a child of another scene: - -* In the Scene Editor **Entity Tree** (left by default), drag the scene onto the scene you want to make its parent. - -* Drag the scene from the **Asset View** (bottom by default) onto the scene you want to make its parent in the **Entity Tree**. - -* In the scene **Property Grid** (on the right by default), next to **Parent**, specify the scene you want to be the scene's parent. - - ![Properties parent scene](media/properties-parent-scene.png) +To make a scene a child of another scene drag the scene from the **Asset View** (bottom by default) onto the scene you want to make its parent in the **Entity Tree**. ## Set the default scene diff --git a/en/manual/game-studio/media/add-scene.png b/en/manual/game-studio/media/add-scene.png deleted file mode 100644 index 0c5754fde..000000000 --- a/en/manual/game-studio/media/add-scene.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f3591ba40138985231bcc1867ddbeb96bc4ef686fcc2600aa77d72f397ad895c -size 25398 diff --git a/en/manual/game-studio/media/add-scene.webp b/en/manual/game-studio/media/add-scene.webp new file mode 100644 index 000000000..58c416a44 --- /dev/null +++ b/en/manual/game-studio/media/add-scene.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70af1de7d24067b489f21f0ff52f6c112536d32e335761edbcc98410b1cb807e +size 13074 diff --git a/en/manual/game-studio/media/properties-parent-scene.png b/en/manual/game-studio/media/properties-parent-scene.png deleted file mode 100644 index bf601b293..000000000 --- a/en/manual/game-studio/media/properties-parent-scene.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:7b5a281ab06554fbb282e4c1bfe2f4d8d1aeaa5c5fb61328a0cb8469c94a1eb3 -size 7361 diff --git a/en/manual/game-studio/media/settings-key-bindings.png b/en/manual/game-studio/media/settings-key-bindings.png deleted file mode 100644 index c716eca30..000000000 --- a/en/manual/game-studio/media/settings-key-bindings.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:a0452f6eb2df0d5c3d22a705fd813f2e4314f80df53510ef0fd27940bbcee81a -size 26564 diff --git a/en/manual/game-studio/media/settings-key-bindings.webp b/en/manual/game-studio/media/settings-key-bindings.webp new file mode 100644 index 000000000..6319a945b --- /dev/null +++ b/en/manual/game-studio/media/settings-key-bindings.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c7c06f9d186c605c2c490eb6fcb73079c335c01ba165703ec4b174a4a2ff483 +size 17208 diff --git a/en/manual/game-studio/navigate-in-the-scene-editor.md b/en/manual/game-studio/navigate-in-the-scene-editor.md index b4515022e..34a962913 100644 --- a/en/manual/game-studio/navigate-in-the-scene-editor.md +++ b/en/manual/game-studio/navigate-in-the-scene-editor.md @@ -78,7 +78,7 @@ Focus | F (with entity selected) > [!TIP] > You can change the scene navigator controls in **Edit > Settings** under **Scene Editor > Key bindings**. -> ![Key bindings](media/settings-key-bindings.png) +> ![Key bindings](media/settings-key-bindings.webp) ## Change camera editor perspective diff --git a/en/manual/input/gamecontrollers.md b/en/manual/input/gamecontrollers.md new file mode 100644 index 000000000..1667b0427 --- /dev/null +++ b/en/manual/input/gamecontrollers.md @@ -0,0 +1,131 @@ +# Gamepads + +Beginner +Programmer + +**Gamepads**, such as the Xbox Elite Wireless Controller and the PS4 DualShock, are popular input devices for consoles and desktop. + +> [!Note] +> Stride is currently optimized for the Xbox Elite gamepad. Other controllers work, but might have unexpected button mappings. Gamepad-specific features like the PS4 DualShock touchpad aren't supported. + +## Digital and analog buttons + +* **Digital** buttons have two states: **up** and **down**. The D-pad, Start, Back, Thumbstick (press), A, B, X and Y buttons are digital buttons. + +* **Analog** buttons return a value depending on how hard the user presses. The triggers are analog buttons, and return a value between 0 and 1. The thumbsticks are also analog, and return values between -1 and 1 on the X and Y axes. + +The Xbox Elite controller buttons have the following names in Stride: + +![Xbox gamepad](media/input-gamepad-standard-gamepad.png) + +## Handle gamepad input + +### Check that gamepads are connected + +Before handling gamepad input: + +* To check if any gamepads are connected, use [InputManager.HasGamePad](xref:Stride.Input.InputManager.HasGamePad). + +* To check how many gamepads are connected, use [InputManager.GamePadCount](xref:Stride.Input.InputManager.GamePadCount). + +* To check if the current device has been disconnected, use the [InputManager.DeviceRemoved](xref:Stride.Input.InputManager.DeviceRemoved) event. + +* To check if a device has been connected, use the [InputManager.DeviceAdded](xref:Stride.Input.InputManager.DeviceAdded) event. + +### Digital buttons + +To query the states and state changes of digital gamepad buttons, on the `GamePad` object, call: + +| Method | Functionality +|--------|-------------- +| [IsButtonDown(IGamePadDevice, GamePadButton)](xref:Stride.Input.GamePadDeviceExtensions.IsButtonDown\(Stride.Input.IGamePadDevice,Stride.Input.GamePadButton\)) | Checks whether the button is in the _down_ state. +| [IsButtonPressed(IGamePadDevice, GamePadButton)](xref:Stride.Input.GamePadDeviceExtensions.IsButtonPressed\(Stride.Input.IGamePadDevice,Stride.Input.GamePadButton\)) | Checks whether the user has _pressed_ the button since the previous update. +| [IsButtonReleased(IGamePadDevice, GamePadButton)](xref:Stride.Input.GamePadDeviceExtensions.IsButtonReleased\(Stride.Input.IGamePadDevice,Stride.Input.GamePadButton\)) | Checks whether the user has _released_ the button since the previous update. + +**Button (GamePadButton)** is the gamepad button you want to check. + +You can also get the state of digital buttons using [GamePadState.Buttons](xref:Stride.Input.GamePadState.Buttons). + +> [!Note] +> The [GamePadState.Buttons](xref:Stride.Input.GamePadState.Buttons) field is a bitmask that uses binary system. Depending on the bitmask value, you can determine which buttons are *up* or *down*. + +To get the gamepad state, use [IGamePadDevice.State](xref:Stride.Input.IGamePadDevice.State). + +### Analog buttons + +To query values of analog buttons, first get the current state of gamepad using +[GetGamePadByIndex(index)](xref:Stride.Input.InputManager.GetGamePadByIndex\(System.Int32\)), where _index (Integer)_ is the index of the gamepad you want to check. + +> [!WARNING] +> The value returned by [IGamePadDevice.State](xref:Stride.Input.IGamePadDevice.State) is the state of the gamepad at the **current** update. You can't reuse this value for the next updates. You have to query it again in every update. + +To get trigger and thumbstick positions, use these +[GamePadState](xref:Stride.Input.GamePadState) fields: + +| Field | Description +|-------|------------ +| [GamePadState.LeftThumb](xref:Stride.Input.GamePadState.LeftThumb) | Left thumbstick X-axis/Y-axis value in the range [-1.0f, 1.0f] for both axes. | +| [GamePadState.RightThumb](xref:Stride.Input.GamePadState.RightThumb) | Right thumbstick X-axis/Y-axis value in the range [-1.0f, 1.0f] for both axes. | +| [GamePadState.LeftTrigger](xref:Stride.Input.GamePadState.LeftTrigger) | Left trigger analog control value in the range [0, 1.0f] for a single axes. | +| [GamePadState.RightTrigger](xref:Stride.Input.GamePadState.RightTrigger) | Right trigger analog control value in the range [0, 1.0f] for a single axis. | + +Thumbsticks move along the X and Y axes. Their positions read as follows: + +![Query thumb position](media/index-gamepad-stick-position-1.png) +![Query thumb position](media/index-gamepad-stick-position-2.png) + +Triggers move along the X axis. Their positions read as follows: + +![Query trigger position](media/index-gamepad-trigger-position.png) + +### Vibration + +To set the gamepad vibration level, use [IGamePadDevice.SetVibration](xref:Stride.Input.IGamePadDevice.SetVibration\(System.Single,System.Single,System.Single,System.Single\)). + +> [!Note] +> Stride currently only supports vibration for Xbox gamepads. + +## Example code + +```cs +using Stride.Core.Mathematics; +using Stride.Engine; + +public class TestScript : SyncScript +{ + public override void Update() + { + //Check if a gamepad is connected + if (Input.HasGamePad) + { + //Get the number of connected gamepads + int gamepadCount = Input.GamePadCount; + + // Check each gamepad's status + foreach(var gamepad in Input.GamePads) + { + // Get the analog thumbstick positions + Vector2 speed = gamepad.State.LeftThumb; + Vector2 direction = gamepad.State.RightThumb; + + // Get the digital buttons' status + if (gamepad.IsButtonDown(GamePadButton.X)) + { + // The action repeats for as long as the user holds the button down. + // This is useful for continuous actions such as firing a machine gun. + } + if (gamepad.IsButtonPressed(GamePadButton.A)) + { + // The action is triggered only once, even if the user holds the button down. + // This is useful for one-time actions such as jumping. + } + } + } + } +} +``` + +## See also +* [Keyboards](keyboards.md) +* [Virtual buttons](virtual-buttons.md) +* [Input overview](index.md) \ No newline at end of file From fb1beba988695d6ec4184fc0983b97fb62be0a02 Mon Sep 17 00:00:00 2001 From: w0wca7a Date: Sun, 8 Feb 2026 23:56:48 +0300 Subject: [PATCH 4/4] Revert "Update Scene pages and images" This reverts commit d531b16526555d7e21ef186a2e3d7526066a04e9. --- en/manual/game-studio/create-a-scene.md | 10 +- en/manual/game-studio/manage-scenes.md | 10 +- en/manual/game-studio/media/add-scene.png | 3 + en/manual/game-studio/media/add-scene.webp | 3 - .../media/properties-parent-scene.png | 3 + .../media/settings-key-bindings.png | 3 + .../media/settings-key-bindings.webp | 3 - .../navigate-in-the-scene-editor.md | 2 +- en/manual/input/gamecontrollers.md | 131 ------------------ 9 files changed, 27 insertions(+), 141 deletions(-) create mode 100644 en/manual/game-studio/media/add-scene.png delete mode 100644 en/manual/game-studio/media/add-scene.webp create mode 100644 en/manual/game-studio/media/properties-parent-scene.png create mode 100644 en/manual/game-studio/media/settings-key-bindings.png delete mode 100644 en/manual/game-studio/media/settings-key-bindings.webp delete mode 100644 en/manual/input/gamecontrollers.md diff --git a/en/manual/game-studio/create-a-scene.md b/en/manual/game-studio/create-a-scene.md index e2c08e0aa..3f9c9b394 100644 --- a/en/manual/game-studio/create-a-scene.md +++ b/en/manual/game-studio/create-a-scene.md @@ -11,9 +11,15 @@ You can create scenes like any other asset. As they are complex assets, they hav 1. In the **Asset View** (by default in the bottom pane), click **Add asset** and select **Scenes**. - ![Add a scene](media/add-scene.webp) + ![Add a scene](media/add-scene.png) -2. Select the **Scene**. +2. Select the appropriate **scene template**. + + Template | Result + ---------|-------- + Empty scene | An empty scene with no entities or preconfigured rendering pipeline + Scene with HDR pipeline | A scene containing basic entities and preconfigured for HDR rendering + Scene with LDR pipeline | A scene containing basic entities and preconfigured for LDR rendering ## Open a scene in the Scene Editor diff --git a/en/manual/game-studio/manage-scenes.md b/en/manual/game-studio/manage-scenes.md index aad73c902..5e3d8a1ff 100644 --- a/en/manual/game-studio/manage-scenes.md +++ b/en/manual/game-studio/manage-scenes.md @@ -21,7 +21,15 @@ Scenes are kept in different folders. This means that different people can work The relationship between parent and child scenes is set on the child, not the parent. In other words, child scenes know about their parent scenes, but parent scenes don't know about their child scenes. -To make a scene a child of another scene drag the scene from the **Asset View** (bottom by default) onto the scene you want to make its parent in the **Entity Tree**. +There are several ways to make a scene a child of another scene: + +* In the Scene Editor **Entity Tree** (left by default), drag the scene onto the scene you want to make its parent. + +* Drag the scene from the **Asset View** (bottom by default) onto the scene you want to make its parent in the **Entity Tree**. + +* In the scene **Property Grid** (on the right by default), next to **Parent**, specify the scene you want to be the scene's parent. + + ![Properties parent scene](media/properties-parent-scene.png) ## Set the default scene diff --git a/en/manual/game-studio/media/add-scene.png b/en/manual/game-studio/media/add-scene.png new file mode 100644 index 000000000..0c5754fde --- /dev/null +++ b/en/manual/game-studio/media/add-scene.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3591ba40138985231bcc1867ddbeb96bc4ef686fcc2600aa77d72f397ad895c +size 25398 diff --git a/en/manual/game-studio/media/add-scene.webp b/en/manual/game-studio/media/add-scene.webp deleted file mode 100644 index 58c416a44..000000000 --- a/en/manual/game-studio/media/add-scene.webp +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:70af1de7d24067b489f21f0ff52f6c112536d32e335761edbcc98410b1cb807e -size 13074 diff --git a/en/manual/game-studio/media/properties-parent-scene.png b/en/manual/game-studio/media/properties-parent-scene.png new file mode 100644 index 000000000..bf601b293 --- /dev/null +++ b/en/manual/game-studio/media/properties-parent-scene.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b5a281ab06554fbb282e4c1bfe2f4d8d1aeaa5c5fb61328a0cb8469c94a1eb3 +size 7361 diff --git a/en/manual/game-studio/media/settings-key-bindings.png b/en/manual/game-studio/media/settings-key-bindings.png new file mode 100644 index 000000000..c716eca30 --- /dev/null +++ b/en/manual/game-studio/media/settings-key-bindings.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0452f6eb2df0d5c3d22a705fd813f2e4314f80df53510ef0fd27940bbcee81a +size 26564 diff --git a/en/manual/game-studio/media/settings-key-bindings.webp b/en/manual/game-studio/media/settings-key-bindings.webp deleted file mode 100644 index 6319a945b..000000000 --- a/en/manual/game-studio/media/settings-key-bindings.webp +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3c7c06f9d186c605c2c490eb6fcb73079c335c01ba165703ec4b174a4a2ff483 -size 17208 diff --git a/en/manual/game-studio/navigate-in-the-scene-editor.md b/en/manual/game-studio/navigate-in-the-scene-editor.md index 34a962913..b4515022e 100644 --- a/en/manual/game-studio/navigate-in-the-scene-editor.md +++ b/en/manual/game-studio/navigate-in-the-scene-editor.md @@ -78,7 +78,7 @@ Focus | F (with entity selected) > [!TIP] > You can change the scene navigator controls in **Edit > Settings** under **Scene Editor > Key bindings**. -> ![Key bindings](media/settings-key-bindings.webp) +> ![Key bindings](media/settings-key-bindings.png) ## Change camera editor perspective diff --git a/en/manual/input/gamecontrollers.md b/en/manual/input/gamecontrollers.md deleted file mode 100644 index 1667b0427..000000000 --- a/en/manual/input/gamecontrollers.md +++ /dev/null @@ -1,131 +0,0 @@ -# Gamepads - -Beginner -Programmer - -**Gamepads**, such as the Xbox Elite Wireless Controller and the PS4 DualShock, are popular input devices for consoles and desktop. - -> [!Note] -> Stride is currently optimized for the Xbox Elite gamepad. Other controllers work, but might have unexpected button mappings. Gamepad-specific features like the PS4 DualShock touchpad aren't supported. - -## Digital and analog buttons - -* **Digital** buttons have two states: **up** and **down**. The D-pad, Start, Back, Thumbstick (press), A, B, X and Y buttons are digital buttons. - -* **Analog** buttons return a value depending on how hard the user presses. The triggers are analog buttons, and return a value between 0 and 1. The thumbsticks are also analog, and return values between -1 and 1 on the X and Y axes. - -The Xbox Elite controller buttons have the following names in Stride: - -![Xbox gamepad](media/input-gamepad-standard-gamepad.png) - -## Handle gamepad input - -### Check that gamepads are connected - -Before handling gamepad input: - -* To check if any gamepads are connected, use [InputManager.HasGamePad](xref:Stride.Input.InputManager.HasGamePad). - -* To check how many gamepads are connected, use [InputManager.GamePadCount](xref:Stride.Input.InputManager.GamePadCount). - -* To check if the current device has been disconnected, use the [InputManager.DeviceRemoved](xref:Stride.Input.InputManager.DeviceRemoved) event. - -* To check if a device has been connected, use the [InputManager.DeviceAdded](xref:Stride.Input.InputManager.DeviceAdded) event. - -### Digital buttons - -To query the states and state changes of digital gamepad buttons, on the `GamePad` object, call: - -| Method | Functionality -|--------|-------------- -| [IsButtonDown(IGamePadDevice, GamePadButton)](xref:Stride.Input.GamePadDeviceExtensions.IsButtonDown\(Stride.Input.IGamePadDevice,Stride.Input.GamePadButton\)) | Checks whether the button is in the _down_ state. -| [IsButtonPressed(IGamePadDevice, GamePadButton)](xref:Stride.Input.GamePadDeviceExtensions.IsButtonPressed\(Stride.Input.IGamePadDevice,Stride.Input.GamePadButton\)) | Checks whether the user has _pressed_ the button since the previous update. -| [IsButtonReleased(IGamePadDevice, GamePadButton)](xref:Stride.Input.GamePadDeviceExtensions.IsButtonReleased\(Stride.Input.IGamePadDevice,Stride.Input.GamePadButton\)) | Checks whether the user has _released_ the button since the previous update. - -**Button (GamePadButton)** is the gamepad button you want to check. - -You can also get the state of digital buttons using [GamePadState.Buttons](xref:Stride.Input.GamePadState.Buttons). - -> [!Note] -> The [GamePadState.Buttons](xref:Stride.Input.GamePadState.Buttons) field is a bitmask that uses binary system. Depending on the bitmask value, you can determine which buttons are *up* or *down*. - -To get the gamepad state, use [IGamePadDevice.State](xref:Stride.Input.IGamePadDevice.State). - -### Analog buttons - -To query values of analog buttons, first get the current state of gamepad using -[GetGamePadByIndex(index)](xref:Stride.Input.InputManager.GetGamePadByIndex\(System.Int32\)), where _index (Integer)_ is the index of the gamepad you want to check. - -> [!WARNING] -> The value returned by [IGamePadDevice.State](xref:Stride.Input.IGamePadDevice.State) is the state of the gamepad at the **current** update. You can't reuse this value for the next updates. You have to query it again in every update. - -To get trigger and thumbstick positions, use these -[GamePadState](xref:Stride.Input.GamePadState) fields: - -| Field | Description -|-------|------------ -| [GamePadState.LeftThumb](xref:Stride.Input.GamePadState.LeftThumb) | Left thumbstick X-axis/Y-axis value in the range [-1.0f, 1.0f] for both axes. | -| [GamePadState.RightThumb](xref:Stride.Input.GamePadState.RightThumb) | Right thumbstick X-axis/Y-axis value in the range [-1.0f, 1.0f] for both axes. | -| [GamePadState.LeftTrigger](xref:Stride.Input.GamePadState.LeftTrigger) | Left trigger analog control value in the range [0, 1.0f] for a single axes. | -| [GamePadState.RightTrigger](xref:Stride.Input.GamePadState.RightTrigger) | Right trigger analog control value in the range [0, 1.0f] for a single axis. | - -Thumbsticks move along the X and Y axes. Their positions read as follows: - -![Query thumb position](media/index-gamepad-stick-position-1.png) -![Query thumb position](media/index-gamepad-stick-position-2.png) - -Triggers move along the X axis. Their positions read as follows: - -![Query trigger position](media/index-gamepad-trigger-position.png) - -### Vibration - -To set the gamepad vibration level, use [IGamePadDevice.SetVibration](xref:Stride.Input.IGamePadDevice.SetVibration\(System.Single,System.Single,System.Single,System.Single\)). - -> [!Note] -> Stride currently only supports vibration for Xbox gamepads. - -## Example code - -```cs -using Stride.Core.Mathematics; -using Stride.Engine; - -public class TestScript : SyncScript -{ - public override void Update() - { - //Check if a gamepad is connected - if (Input.HasGamePad) - { - //Get the number of connected gamepads - int gamepadCount = Input.GamePadCount; - - // Check each gamepad's status - foreach(var gamepad in Input.GamePads) - { - // Get the analog thumbstick positions - Vector2 speed = gamepad.State.LeftThumb; - Vector2 direction = gamepad.State.RightThumb; - - // Get the digital buttons' status - if (gamepad.IsButtonDown(GamePadButton.X)) - { - // The action repeats for as long as the user holds the button down. - // This is useful for continuous actions such as firing a machine gun. - } - if (gamepad.IsButtonPressed(GamePadButton.A)) - { - // The action is triggered only once, even if the user holds the button down. - // This is useful for one-time actions such as jumping. - } - } - } - } -} -``` - -## See also -* [Keyboards](keyboards.md) -* [Virtual buttons](virtual-buttons.md) -* [Input overview](index.md) \ No newline at end of file