Input Mapping DSL

By using the Input Mapping domain-specific language, it is a matter of seconds for you to add input mappings to your FlatRedBall/XNA game. The currently supported input mappings are those from Xbox 360 controller buttons to XNA keyboard keys.

After installing the InputMappingDSL, right-click your game project then Add -> New Item. Select Input Mapping from the list, give your input mapping a name (such as Player1InputMapping) and then click in Add.

01-NewInputMapping.png

A new Input Mapping editor opens, integrated into Visual Studio, as you can see below:

02-ModelingExperience.png

Notice that the Mapping Name and the Code generation Namespace fields were already filled for you, based on the file name and project root namespace. Feel free to change those fields.

To add a new mapping from a Xbox 360 controller button, just hover the mouse over the button in the controller image and double-click it. For example, let's add a mapping from the controller's X button to the ENTER keyboard key. When hovering the mouse over the X button in the controller image, a note in the right side tells that it is not currently mapped to any key yet.

03-HoverOver.png

Double-click the X button in the controller image to add and remove mappings. A dialog opens with all current mappings for the button (in our case, none):

04-MappingsManager.png

Click on the plus (+) sign to add one or more mappings to the button. A list of all possible keyboard keys will be displayed. Select the desired one(s) and click in OK.

05-TargetKeys.png

Back to the previous screen, you can delete previous mappings or click in OK to apply the mappings. Notice that the mapping is confirmed by the status label in the right:

06-MappingConfirmed.png

You can then use the controls below to tell which players are targeted by this mappings file, and whether the mapping should be performed only if the Xbox 360 controller is disconnected.

07-ExtraControls.png

After you are done, click in the Transform All Templates button in the Solution Explorer window to generate code.

08-TransformAllTemplates.png

Notice that a .cs code file class was created for you, just under the <mapping name>.tt file. It contains a class whose name matches your mapping name, as well as a ApplyMappings static method that you can call in the Initialize method of your game class.

09-CodeGeneration.png

Finally, notice the Apply Common Mappings... button in the input mapping designer. From there, you can very quickly apply common input mappings to your game, such as the D-Pad (or an analog stick) to the keyboard arrows.

10-ApplyCommonMappings.png

As a final tip, if you want to more quickly delete a set of input mappings, you can do that from the InputMappingDSL Explorer window, as shown below. If it is not visible, you can find it through the menu View -> Other Windows.

11-InputMappingDSLExplorer.png

Summing up, the powerful FlatRedBall's input mapping features are now easier to use through visual designers and more abstraction.

Happy gaming!
-- AFurtado

Last edited Dec 14, 2008 at 12:52 PM by AFurtado, version 6

Comments

No comments yet.