Browse Source

Add vibration test button to core_input_gamepad (#5362)

pull/5364/head
Serhii Zasenko 2 weeks ago
committed by GitHub
parent
commit
f51204821a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 0 deletions
  1. +10
    -0
      examples/core/core_input_gamepad.c

+ 10
- 0
examples/core/core_input_gamepad.c View File

@ -72,6 +72,8 @@ int main(void)
if (IsKeyPressed(KEY_LEFT) && gamepad > 0) gamepad--;
if (IsKeyPressed(KEY_RIGHT)) gamepad++;
Vector2 mousePosition = GetMousePosition();
bool mousePressed = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
if (IsGamepadAvailable(gamepad))
{
@ -262,6 +264,14 @@ int main(void)
DrawText(TextFormat("AXIS %i: %.02f", i, GetGamepadAxisMovement(gamepad, i)), 20, 70 + 20*i, 10, DARKGRAY);
}
Rectangle vibrateButton = (Rectangle){10, 70 + 20*GetGamepadAxisCount(gamepad) + 20, 75, 10};
if (mousePressed && CheckCollisionPointRec(mousePosition, vibrateButton)){
SetGamepadVibration(gamepad, 1.0, 1.0, 1.0);
}
DrawRectangleRec(vibrateButton, SKYBLUE);
DrawText("VIBRATE", vibrateButton.x + 14, vibrateButton.y + 1, 10, DARKGRAY);
if (GetGamepadButtonPressed() != GAMEPAD_BUTTON_UNKNOWN) DrawText(TextFormat("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED);
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY);
}

Loading…
Cancel
Save