Skip to content

Commit f512048

Browse files
authored
Add vibration test button to core_input_gamepad (#5362)
1 parent a24e65d commit f512048

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

examples/core/core_input_gamepad.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ int main(void)
7272

7373
if (IsKeyPressed(KEY_LEFT) && gamepad > 0) gamepad--;
7474
if (IsKeyPressed(KEY_RIGHT)) gamepad++;
75+
Vector2 mousePosition = GetMousePosition();
76+
bool mousePressed = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
7577

7678
if (IsGamepadAvailable(gamepad))
7779
{
@@ -262,6 +264,14 @@ int main(void)
262264
DrawText(TextFormat("AXIS %i: %.02f", i, GetGamepadAxisMovement(gamepad, i)), 20, 70 + 20*i, 10, DARKGRAY);
263265
}
264266

267+
Rectangle vibrateButton = (Rectangle){10, 70 + 20*GetGamepadAxisCount(gamepad) + 20, 75, 10};
268+
if (mousePressed && CheckCollisionPointRec(mousePosition, vibrateButton)){
269+
SetGamepadVibration(gamepad, 1.0, 1.0, 1.0);
270+
}
271+
DrawRectangleRec(vibrateButton, SKYBLUE);
272+
273+
DrawText("VIBRATE", vibrateButton.x + 14, vibrateButton.y + 1, 10, DARKGRAY);
274+
265275
if (GetGamepadButtonPressed() != GAMEPAD_BUTTON_UNKNOWN) DrawText(TextFormat("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED);
266276
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY);
267277
}

0 commit comments

Comments
 (0)