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.


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


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.


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):


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.


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:


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.


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


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.


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.


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.


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 1:52 PM by AFurtado, version 6


No comments yet.