-
Notifications
You must be signed in to change notification settings - Fork 3
Tutorials
Adérito Silva edited this page Jun 22, 2022
·
15 revisions
This page contains tutorials about how to implement common functionality related to gamepads on your application, using XInputium. Because different game or application frameworks use different means for performing the same tasks, the tutorials in this page will assume a generic fictional application framework, instead of using specific existing frameworks, unless specified otherwise.
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
XGamepad gamepad = new();
XButtons jumpButton = XButtons.A; // The jump button.
double maxJumpHoldTime = 750; // Button hold time for the highest jump, in milliseconds.
// Register a dynamic event that fires when the button is released or when the
// button is held for the `maxJumpHoldTime`, whatever happens first.
gamepad.RegisterActivationInputEvent(
() => gamepad.Buttons.IsPressed(jumpButton),
TimeSpan.Zero, TimeSpan.Zero,
TimeSpan.FromMilliseconds(maxJumpHoldTime),
ActivationInputEventTriggerMode.OnDeactivation,
(s, e) =>
{
// Determine the jump force, using the duration of the button hold.
float jumpForce = (float)(e.PreviousStateDuration.TotalMilliseconds / maxJumpHoldTime);
// Make the jump force non-linear, so pressing the button shortly will not jump
// with a too low force. Optionally, we could also set a minimum jump force.
jumpForce = NonLinearFunctions.QuadraticEaseOut(jumpForce);
// Call our method that will make the game character jump.
Jump(jumpForce);
});
// Call this on every game/application frame.
gamepad.Update();
// Make the character jump, with a force within the 0-1 range.
void Jump(float force)
{
Debug.WriteLine($"Jump! (force: {force:P0})");
}TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
The wiki is currently a work in progress, and some pages may be missing or incomplete. Thank you for your understanding!