-
Notifications
You must be signed in to change notification settings - Fork 3
Tutorials
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
A common ability game characters have in many games is the ability to jump. It is pretty common to make these jumps dynamic, by allowing the user to tap a button to make a short jump, or holding the button for longer to make a higher jump. In the following example, we will see how one could implement this functionality on a game. There are several ways for doing this, but we will use the versatility of ActivationInputEvent to achieve it.
XGamepad gamepad = new(); // Our application-wide gamepad instance.
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})");
}On our example above, if the user holds A button for less than 750 milliseconds, a fraction of the max jump force is used to jump. Once that time has passed, if the user is still holding the button, the character jumps anyway, with the maximum jump force. The jump force depends on how long the user holds the button, and that time affects the jump force non-linearly.
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!