Watch
2
0
Fork
You've already forked raylib-cs
0

Fixed problem where Xbox controller wouldn't appear for InputGamepad.

I've fixed the problems associated with this file which I detailed in my issue report [here](https://github.com/ChrisDill/Raylib-cs/issues/195) (issue #195).

My version of Raylib-cs is slightly different from the bleeding edge master branch but still recent, and my project setup is slightly different too, but I think this change should still work. You should test it to double check though.
This commit is contained in:
WraithGlade 2023-09-07 20:15:01 -04:00 committed by GitHub
commit 356155b5fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,17 +16,19 @@
********************************************************************************************/
using System.Numerics;
using Raylib_cs;
using static Raylib_cs.Raylib;
namespace Examples.Core;
namespace Examples.Core
{
public class InputGamepad
{
// NOTE: Gamepad name ID depends on drivers and OS
// public const string XBOX360_NAME_ID = "Microsoft;
// public const string PS3_NAME_ID = "PLAYSTATION(R)3;
public const string XBOX360_NAME_ID = "Xbox";
public const string PS3_NAME_ID = "PLAYSTATION(R)3";
// These are some possible names the gamepads could have.
public const string XBOX360_LEGACY_NAME_ID = "Xbox Controller";
public const string XBOX360_NAME_ID = "Xbox 360 Controller";
public const string XBOX360_NAME_ID_RPI = "Microsoft X-Box 360 pad";
public const string PS3_NAME_ID = "PLAYSTATION(R)3 Controller";
public static int Main()
{
@ -63,7 +65,9 @@ public class InputGamepad
string gamepadName = GetGamepadName_(0);
DrawText($"GP1: {gamepadName}", 10, 10, 10, Color.BLACK);
if (gamepadName == XBOX360_NAME_ID)
if (gamepadName == XBOX360_LEGACY_NAME_ID ||
gamepadName == XBOX360_NAME_ID ||
gamepadName == XBOX360_NAME_ID_RPI)
{
DrawTexture(texXboxPad, 0, 0, Color.DARKGRAY);
@ -143,7 +147,7 @@ public class InputGamepad
DrawCircle(259, 152, 34, Color.LIGHTGRAY);
DrawCircle(
259 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
152 - (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
152 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
25,
Color.BLACK
);
@ -152,8 +156,8 @@ public class InputGamepad
DrawCircle(461, 237, 38, Color.BLACK);
DrawCircle(461, 237, 33, Color.LIGHTGRAY);
DrawCircle(
461 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
237 - (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
461 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_X) * 20),
237 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_Y) * 20),
25, Color.BLACK
);
@ -322,3 +326,4 @@ public class InputGamepad
return 0;
}
}
}