IInputCommand Interface |
Namespace: DigitalRune.Game.Input
The IInputCommand type exposes the following members.
Name | Description | |
---|---|---|
Update |
Updates internal values of this command. This method is called automatically in each frame
by the input service.
|
Name | Description | |
---|---|---|
InputService |
Gets or sets the input service.
| |
Name |
Gets the name.
(Inherited from INamedObject.) | |
Value |
Gets the value.
|
Input commands translate raw input into (such as button presses, key combinations, etc.) to semantic actions (such as "Forward", "Jump", "Shoot", etc.).Input commands are managed by the InputService. Input commands can be added or removed from the input service by adding or removing them from the Commands collection. The input commands are identified by their Name in the Commands collection.
When the input service is updated it calls the method Update(TimeSpan) of all registered input commands. In this method the input commands can check the user input and update their Value accordingly. For example, the input command "Jump" might check whether the user has pressed the SPACE key and set the value to 1 if the key is down.
Other game components can check the command and do not need to know which user input triggered the action. For example:
if (InputService.Commands["Jump"].Value > 0) { // Let the player character jump. ... }
Input commands should have a unique Name. The name must not be changed while the command is added to an IInputService. Here are examples for command names in a game: "Forward", "Strafe", "Turn", "Jump", "Shoot", etc. Typically, command names describe the intention of the player.
The Value indicates whether the command is active. A value of 0 indicates that the action is inactive. A value of 1 typically indicates that the command is active - the user wants to perform the action. Depending on the type of action, the value can also be negative. For example, the "Forward" command might use a value of 1 to indicate that the user wants to move forward and a value of -1 to indicate that the user wants to move backward. A value of 0.5 can indicate that the user wants to move with half speed, which can result from an analog input device.
The property InputService is automatically set when the command is added to an input service. The method Update(TimeSpan) is called in each frame by the InputService to do any time intensive work. For instance, if the command smooths input values using a low-pass filter, this is best done in the Update(TimeSpan) method.
This interface does not define how commands use the IsHandled flags (IsKeyboardHandled, etc.) of the input service.