Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The AnalogButton class is used for hardware which can report a single value, typically between 0 and 1. The most common example of an analog button is the trigger buttons on the Xbox360GamePad.
The following shows how to use the right trigger on an Xbox360GamePad to assign the movement speed of a SpaceShip entity:
[subpages depth="1"]
The IsMaxPositionNormalized property controls whether to normalize (keep less than 1) the AnalogStick's Position value. If false, the analog stick will return its raw input value which may be larger than 1. Games which use the analog stick for movement and which would like to restrict the movement to a maximum value (such as a top-down game) should set IsMaxPositionNormalized to true.
The AnalogStick class provides a variety of information about an AnalogStick on an Xbox360GamePad.
The Xbox360GamePad class exposes two analog sticks: LeftStick and RightStick. The following code will move a Sprite according to how the LeftStick is positioned: Add the following at class scope:
Add the following to Initialize after initializing FlatRedBall:
Add the following to Update:
The analog stick can report information as if it were a DPad, which is useful for games where you control an object or UI over a discrete set of positions, such as moving a selection cursor over a grid of characters in a fighting game. The following code shows how to move a Sprite by 16 pixels in any direction:
The AsDPadRepeatRate method results in the AnalogStick behaving as a DPad with repeat-rate logic. In other words, when the user holds the AnalogStick initially pushes the analog stick in a direction, the AsDPadRepeatRate method returns true. It keeps track of the last time it returned true and will continue to return true at a set frequency so long as the user holds the AnalogStick in that direction. The following code creates a Sprite which is moved .5 units every time the analog stick is pressed or whenever the push triggers through the repeat-rate logic. Add the following at class scope:
Add the following to Initialize after initializing FlatRedBall:
Add the following to Update:
The amount of time between the initial push and the first repeat is longer than the space between subsequent repeats. This is similar to the repeat rate resulting from holding down a key on the keyboard.
[subpages depth="1"]
InputDeviceBase is a base class for implementing a custom InputDevice. The InputDeviceBase provides default implementation for all IInputDevice properties, allowing derived classes to override only some of the available properties. The InputDeviceBase class can also be instantiated to create an IInputDevice-implementing instance which returns 0 and false for all properties.
InputDeviceBase can be used in the following situations:
To wrap input which is read from some input hardware which is not natively supported by FlatRedBall, such as a custom game controller.
To remap controls, such as to change the default horizontal and veritcal movement on a keyboard from WASD to arrow keys.
To implement AI on a top down or platformer entity. For an example on how to perform this, see the Enemy Input Logic tutorial.
The IMouseOver interface is an interface that is used to standardize checks between an object and the Cursor.
The following code checks to see if the Cursor is over an AxisAlignedRectangle. This example was created inside an Entity which contains an AxisAlignedRectangle instance called AxisAlignedRectangleInstance:
Add the following to CustomInitialize to force the cursor to be visible:
Add the following to CustomActivity:
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
The I2DInput interface can be used to generalize input code for detecting a value and velocity along two dimensions (X and Y). A common usage of this is to control an object's 2-dimensional movement such as a character in a top-down game. Examples of input devices implemented as I2DInput are the GamePad AnalogStick and the GamePad DPad. The X and Y properties typically return values between -1 and 1.
The following shows how to move an entity horizontally and vertically using I2DInput. It assumes that the code has an Entity called Character. Note - this example assumes your entity does not already implement the Top Down input movement in Glue. If it does, you will have compile errors.
In Character.cs:
In the Screen's CustomInitialize, assuming it has a CharacterInstance:
The following shows how to use the most common FRB input classes to get a I2DInput:
Keyboard
Xbox360GamePad DPad
Xbox360GamePad AnalogStick
The Magnitude property returns the distance away from (0,0) that is returned by the input device. By default most input devices return an X and Y value of (0,0) which would indicate a magnitude of 0. If the values are non-zero, then the magnitude will also be non-zero. Typically the Magnitude is between 0 and 1.
I2DInput provides an extension method for combining multiple controls. The Or method allows combining multiple input devices to create a single I2DInput instance. For example, you may be developing a game where the player can be moved with both the keyboard and gamepad. When multiple inputs are combined using Or, the largest of either inputs will be used. For example, if one input device returns an X of 0.5f, and the other returns an X value of 1, then the value of 1 will be returned by the combined
The Or method can be used to combine any number of inputs to produce a single input. For example, the following code could be used to "Or" the arrow keys with WASD:
The following code can be used to "Or" arrow key movement with an Xbox360GamePad's LeftStick.
The InputManager is a class responsible for reading and reporting input from the keyboard, mouse, and gamepads. It is automatically initiated and updated by FlatRedBallServices so once the Initialization methods are called, the InputManager can be used.
See Keyboard
See Mouse
See TouchScreen
See Xbox360GamePad
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
IPressableInput is an interface which can be used to generalize input code for whether an input device is being pressed down, was just pressed, or was just released. Numerous common input devices are implemented as IPressableInputs.
The following shows how to make an entity perform actions (such as shoot bullets). It assumes that the code has an Entity called Ship, and that Ship has a function called FireBullet.
In Ship.cs:
In the Screen's CustomInitialize, assuming it has a ShipInstance:
The following shows how to use the most common FRB input classes to get IPressableInputs:
The InputReceiver property is a property which can be assigned on the InputManager to identify that a particular object (which must implement the IInputReceiver interface) should receive keyboard input. This property can be used to prevent multiple objects from receiving keyboard input. This is useful if multiple game objects respond to keyboard input - such as a a text box and a character in a platformer.
The InputReceiver can be assigned through custom code. For example, the following might be an event executed when an Entity in Glue is clicked:
For information on how to prevent input, see the IInputReceiver page.
The Clear method clears out input from the Keyboard. After Clear is called, all Keyboard methods and properties will behave as if there was no keyboard activity this frame. This function is useful when implementing functionality that should consume input, and is commonly used with the IInputReceiver interface.
The Keyboard class can be used for text input. Unfortunately, at the time of this writing the keyboard only understands the English keyboard. The GetStringTyped method returns the string that was typed during the last frame. It is possible for multiple keys to be pressed during a frame and the GetStringTyped method also considers whether the Shift key is pressed.
The following code creates a Text object which displays the string typed.
Add the following using statement:
in your Game class scope:
Replace Initialize with the following:
GetStringTyped supports ctrl+c and ctrl+v for copy and paste; however, your game must be set to use [STAThread]. For more information, see this page.
The ControlPositionedObject method is a method which can be used to move a PositionedObject with the arrow keys. this code is rarely used in final games, but can be very useful for learning how to use FlatRedBall and for quick prototypes.
For an example, see this example on the main Keyboard page.
The IgnoreKeyForOneFrame method marks the argument key as being ignored for the rest of the current frame. This is useful if your project has two live objects which are checking for a particular key, but you only want one of them to receive the key press.
In this example we will consider a game screen which uses the Escape key to show a pause menu. Once the pause menu is visible, the Escape key will close it. We will assume that the Pause menu is an instance inside the Screen which has a Visible property (ImplementsIVisible in Glue). Code may look like this:
The code should consume the Escape key by calling IgnoreKeyForOneFrame to prevent both pieces of code from executing in the same frame.
The KeyDown method is a method which returns whether a particular key is being held down. This method will return true if a key is pressed, and will continue to return true until the key has been released. This method can be used to perform every-frame actions such as setting the velocity of a character if the key is pressed.
The following code will move a Sprite to the right if the Right arrow key is down:
The Mouse class provides functionality for grabbing and moving any object which implements the PositionedObject class. This includes common FlatRedBall types like Sprite and Text, as well as entities created in Glue. The following code creates 9 Sprites and allows the user to click and drag to control the Sprites. This code can be added to any FlatRedBall Screen
Setting the GrabbedPositionedObject does the following:
Stores the reference in the GrabbedPositionedObject property
Stores offset variables - this is the difference between the GrabbedPositionedObject's position and the cursor's world coordinates.
Updates the GrabbedPositionedObject's position every frame using the Mouse's world coordinates and the offset values. This is performed automatically - there is no need to manually manage positions when using GrabbedPositionedObject.
In the example above the Sprites do not have any parents so they can be grabbed and moved freely by the cursor. It is common to have Sprites as part of Glue entities, in which case the Sprite is attached to the entity. If the GrabbedPositionedObject has a non-null Parent, then it cannot be moved. In this situation it is more common to grab (and move) the parent entity.
The Mouse class provides functionality for getting input data from the physical mouse. This class is automatically instantiated by and accessible through the InputManager. The Mouse class is not available on the Xbox360 if using FlatRedBall XNA.
There are many ways to get data from the mouse. The following section of code is a series of if-statements which could be used to detect input from the mouse.
The mouse scroll wheel is exposed through the InputManager.Mouse.ScrollWheel property. The ScrollWheel property returns the number of "clicks" that the scroll wheel has moved since last frame. The following code controls the Z position of the camera based on the ScrollWheel property.
See the showing cursor wiki entry.
The Mouse class provides information about the cursor's pixel coordinates.
The mouse coordinates are top left justified, so (0,0) represents the top left corner of the screen. Keep in mind that the pixel coordinates are relative to the top-left of the screen, but not bound by your game screen. That means that if the cursor is to the left (outside of) your game screen, then the X value will be negative. Also, the mouse will continue to return values when the cursor is to the right or below the game screen, resulting in values which are potentially larger than the width or height of the screen.
The Mouse reports the world coordinates of the cursor through the functions WorldXAt and WorldYAt.
For a more detailed example see this entry on moving a Sprite by positioning it to the cursor's coordinates.
Certain activities should only occur if the mouse is in the window. To test for this, use the following code: Add the following using statement:
The following code performs the check:
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
The ModifyMouseState event is an event you can add to the Mouse object to set/modify the Microsoft.Xna.Framework.Input.MouseState used by the mouse for positioning and clicking. This is useful if you are working on a platform which does not have mouse input but you would like to simulate mouse input, or if you are working on a platform which requires modifications of the mouse input.
The following code can be used in a WPF project to properly set the mouse position. Add the following to your Game's Initialize function:
Add the following implementation:
The LastFrameGestures is a List of representing all gestures read last frame. You can use the LastFrameGestures in your code to respond to gesture input. The LastFrameGestures will only be populated every frame if the value is true (default is true). For full documentation on how to use GestureSamples, see the .
Some games benefit from keeping the mouse within the screen bounds. The two common scenarios for keeping the mouse within the screen bounds are:
A first person shooter uses the mouse to move around. The mouse should be invisible and not move outside of the window when the window has focus.
Real time strategy games often implement "edge scrolling" (scrolling the camera when the mouse reaches the edge of the screen).
If the mouse is invisible then the easiest way to keep the mouse in screen is to continually reset its position every frame:
The mouse can be bound to the window as shown in the following code:
Code obtained from http://xboxforums.create.msdn.com/forums/p/3553/18372.aspx
The IsOn3D method is a method which can be used to detect whether the mouse is over a variety of different objects. The reason it is called IsOn3D is because it performs a 3D test (ray cast) so it works regardless of the camera orientation of the orientation of the object being tested.
The following code creates a Text object. This text object will turn white when the mouse moves over the Text, but will remain blue if the mouse is not over it.
Add the following using statements:
Add the following at class scope:
Add the following to Initialize after initializing FlatRedBall:
Add the following to Update:
Warning: You should always use the non-generic version of IsOn3D when performing tests on Text objects. Want to know more? Read on!
There are a number of overloads for the IsOn3D method. The two which apply to the Text object are:
You may be wondering which to use, why there are two versions, and how you can pick which version you are using.
First, you should use the non-generic version. That is, you should use the version that takes a Text argument.
So why are there two versions? The reason is because the generic IsOn3D is a method that is used to test whether the Mouse is over types such as Sprites and SpriteFrames. Since these objects all implement IPositionable, IRotatable, and IReadOnlyScalable, then this generic function works well.
The reason that the Text object can use the generic version of IsOn3D is because it also implements the necessary interfaces; however, even though it implements the IReadOnlyScalable, it is slightly different from the Sprite and SpriteFrame classes.
The Sprite and SpriteFrame classes both are always centered on their position. This means that the right edge of these objects is always X + ScaleX. However, this is not the case for the Text object due to its VerticalAlignment and HorizontalAlignment properties. These properties can change how the Text is drawn relative to its actual position. For this reason, the assumption that the Text's position is at its center is not valid.
This means that if the Text object is centered both horizontally and vertically, then the generic IsOn3D will accurately determine whether the mouse is over the Text. But if either property is not centered, then the generic IsOn3D will not perform accurately.
The non-generic version of IsOn3D (which has a Text argument) can perform Text-specific logic to accurately determine whether the mouse is over the Text object regardless of the HorizontalAlignment or VerticalAlignment.
This brings us to the third question - how can you pick which you are using? This all depends on how you call the method. The following code shows how to call each version:
The following code creates two Cameras. Both cameras view a Sprite. If the cursor is over the Sprite on either Camera then it turns purple.
Add the following using statements:
Add the following at class scope:
Add the following to Initialize after initializing FlatRedBall:
Add the following to Update:
At the time of this writing there is no method to simply return all of the objects that the Mouse is over - instead you will have to manually loop through all objects to test whether the mouse is over the object. This means there are a few things to consider:
Performance may suffer if you have a lot of objects in your scene. If you are suffering from performance issues you may need to perform some type of higher-level partitioning to reduce calls to this method.
You will need to manually loop through objects and maintain a list of objects which you are over if you are interested in performing multiple-selection.
The ReadsGestures variable controls whether the FlatRedBall TouchScreen instance automatically reads gestures from the XNA/MonoGame TouchPanel. This value is true by default. This means that game code will not be able to read from the native MonoGame's TouchPanel since FlatRedBall has already read the gestures (a read clears out the information). If you would like to use MonoGame code to read gestures, then set the ReadGestures to false.
You can read gestures either from XNA or FRB. The following two blocks of code show the two options you have for reading gestures:
The SetScreenPosition method allows for control over the native Windows mouse. This method can be used to override the behavior of the mouse.
The TouchScreen class provides information about the physical touch screen on devices which provide one. This class can be used on Android, iOS, and touch-enabled Windows RT apps. An instance of the TouchScreen class is automatically instantiated and available through the InputManager, so you do not need to instantiate your own. For more information, see the TouchScreen page.
Note: This class does not work for touch screens for Windows 7. Touch screens for Windows 7 are not exposed to the XNA API. You will need to read touch screen input manually. For more information, see this link: http://blogs.msdn.com/b/shawnhar/archive/2010/09/09/touch-input-on-windows-in-xna-game-studio-4-0.aspx
The FlatRedBall TouchScreen provides a thin wrapper and access to the underlying GestureSamples provided by XNA. If you are comfortable using the XNA-provided GestureSample class, you can set the TouchScreen's ReadsGestures property to false. Otherwise, you will want to loop through the LastFrameGestures list and perform actions appropriately.
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
[subpages depth="1"]
The WindowsInputEventManager is a class which can be used to read character-based input from the keyboard (as opposed to key-based input, as provided by the FlatRedBall Keyboard class). Character based input (where character refers to the char type) is useful for games which need to read string input from the keyboard. For example, games may need input for entering a player's name.
The WindowsInputEventManager class is currently only available in the FlatRedBall XNA PC projects. Eventually other platforms will have their own platform-specific classes.
Once added, the WindowsInputEventManager can be accessed in any class because it is static . In this example the code to handle input events exists in a Glue screen.
Notice that CustomDestroy unsubscribes from the events subscribed to in CustomInitialize .
The Xbox360GamePad class represents the current state of a physical game pad. The Xbox360GamePad can provide information about its buttons and DPad with ButtonPushed, ButtonDown, and ButtonReleased methods. You can also get information about the analog sticks using the AnalogSticks references. Information about the trigger buttons can be accessed through the AnalogButton references. The InputManager exposes an array of Xbox360GamePads. There are always 4 elements in this array regardless of the number of game pads connected.
The name Xbox360GamePad exists for historical reasons - XNA originally only exposed support for Xbox36 controllers. Modern versions of FlatRedBall provide support for a variety of hardware including:
Xbox360 and Xbox One controllers
Switch Pro controllers
USB Gamecube controllers
Playstation DualShock
General PC controllers
The Xbox360GamePad class reports whether a button was pushed the last frame, is currently down, or was released. The following code moves a Sprite to the right one unit when the A button is pressed and moves a Sprite to the left when the B button is released:
The following code reports the number of game pads connected at a given time:
The Xbox360GamePad provides two analog sticks:
LeftStick
RightStick
Each property provides information about the matching hardware analog stick. For more information on using the analog stick property, see the AnalogStick page.
See the ButtonMap property.
The following code sets the vibration on the game pad:
The Xbox360GamePads which are part of the InputManager are automatically updated every frame by the engine. This information is not buffered, therefore very rapid button presses may not be ready by the controller.
The Xbox360GamePad name orignally comes from the fact that XNA supported Xbox 360 controllers. Despite its name, the Xbo360GamePad class can be used on most FlatRedBall platforms. As of the time of this writing, the following platforms and hardware are supported.
Desktop GL: Xbox 360 controllers, Xbox One controllers, Switch Pro controllers, USB Gamecube controllers, PlayStation DualShock, Generic PC controllers
Desktop XNA: Xbox 360 controllers, Xbox One controllers
Android: Bluetooth and wired controllers
iOS: Untested
The ButtonMap on the Xbox360GamePad allows for the Keyboard to simulate input for an Xbox360GamePad. By default this value is null, therefore the Keyboard will not simulate any input. Setting this value to a non-null value will enable keyboard simulation.
The following example sets up a button map for the keyboard:
The ButtonDown method returns whether a button is currently being held down. This will be false if the player is not pushing the button, and it will return true every frame that the button is pressed.
The following code shows how to perform logic if the player is holding the A or B buttons on the Xbox360GamePad:
Add the following using statements:
Later, perform the checks:
The DPad on the Xbox360GamePad acts as four separate buttons. Therefore, each direction can be independently checked just like buttons. For example, the following code moves a character according to the left and right DPad.
Buttons are represented by enumerations which can be looped through to check. The first enumeration value is 0, and the last value in the enumeration is Button.LeftStickAsDPadRight. Therefore, the following loop will check all buttons:
The ControlPositionedObject method is a shortcut method which can be used to quickly add control logic for PositionedObjects using a Xbox360GamePad. The ControlPositionedObject method modifies the Velocity values of a PositionedObject. Therefore, consider the following:
Acceleration will not have any impact on a PositionedObject that is being controlled by ControlPositionedObject
ControlPositionedObject sets Velocity even if the left analog stick is not being touched (it will set it to 0).
ControlPositionedObject on Entities which contain shapes will break CollideAgainstBounce calls since CollideAgainstBounce modifies velocity, but the modified velocity will be overridden by ControlPositionedObject. If using CollideAgainstBounce, consider using ControlPositionedObjectAcceleration.
ControlPositionedObject provides control for X, Y, and Z (using the shoulder buttons).
Note: ControlPositionedObject is a method which can be very useful for new programmers, for prototypes, and for simple games. However, most games require more custom controls over their objects. Therefore, you may find that you will need to replace ControlPositionedObject with custom movement code as your project expands. If so, don't worry - you're not doing anything wrong.
Assuming MyEntity is a valid PositionedObject instance:
The following code is the code used in the engine to implement ControlPositionedObject. You can use and modify this code if you'd like to customize how the logic is applied:
ButtonPosition can be used to reference a button based in its physical position rather than by letter. Referencing a button by position can be useful if players are playing your game with gamepads which do not necessarily position their buttons identically.
For example, consider the A, B, X, and Y button positions on the Xbox and Switch controllers.
You may want your game to use the button positions rather than specific button letters when assigning input to your player.
Entities typically use IPressableInput instances to control actions like jumping. Rather than inspecting the gamepad type, games cna use the ButtonPosition to assign input. For example, the following code might be used to assign the JumpInput:
The DeadzoneType property controls how the Deadzone value is applied on an Xbox360GamePad. By default Radial DeadzoneType is used.
The following code sets the first Xbox360GamePad to use a Cross deadzone with a 0.15 value:
The Radial deadzone type treats the position of the analog stick as (0,0) if the position reported by the hardware is within a circle centered at (0,0) with the Deadzone value used as the radius. Visually, this means that any value within the red area would be reduced to (0,0).
Radial deadzones are recommended for top-down (four-way directional) movement games.
The Cross deadzone type treats each axis independently regardless of the value of the other axis. In other words, if the absolute value of X as reported by the hardware is smaller than the Deadzone value, then X will be reported as 0. Visually, this creates a cross deadzone area as shown in the following diagram:
Cross deadzones are recommended for platformer games and games where players may want to move perfectly along a particular axis.
The FakeIsConnected property can force a Xbox360GamePad's IsConnected property to true whether a physical controller is actually connected or not.
Some game logic may depend on the number of connected Xbox360GamePads. For example, a game which supports a local versus mode may enable one character-selection cursor for each connected Xbox360GamePad. You may not have access to four Xbox controllers, but you may want to still test this functionality. The FakeIsConnected enables this.
The Deadzone property can be used to address drift which can occur due to analog stick hardware reporting near-zero values, or due to the user unintentionally pushing the analog slightly in an undesired direction. By default, Xbox360GamePads use a 0.1f Deadzone value. The details of how the Deadzone property is applied can be found in the DeadzoneType page.
The IgnoreButtonForOneFrame method can be used if multiple objects are watching for a particular button to be pushed, but the first one that reacts to it should "consume" it so that no other objects get the button push. This method is very convenient because it does not require any additional logic aside from simply calling this method when consuming the button event.
In this example we have some if statements which increment a number according to button pushes. The first check for the A button will call IgnoreButtonForOneFrame on the A button. The first check for the B button will not. The result is that A will increment the call count by 1, while B will increment the call by 2.
Add the following using statement:
Add the following at class scope:
Add the following in Update:
The DelegateBased1DInput makes it easy to create a I1DInput implementation without creating a custom class. This is especially useful if creating a class which will satisfy multiple input interfaces, such as a custom controller implementation. DelegateBased1DInput can be used similarly to FlatRedBall.Input.DelegateBased2DInput. For a code sample, see the DelegateBased2DInput page.
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.
DelegateBasedPressableInput makes it easy to create a IPressableInput implementation without creating a new class. This is especially useful if creating a class which will satisfy multiple input interfaces, such as a custom controller implementation. The DelegateBasedPressableInput takes three Func<bool> arguments to its constructor as shown in the following signature:
To create a pressable input that is always pressed, you can use the the following code:
The DelegateBased2DInput class allows creating a custom I2DInput implementation without creating a custom class. This is especially useful if creating a class which will satisfy multiple input interfaces, such as a custom controller implementation.
The following code shows how to create a 2D Input that uses the Keyboard's arrow keys:
The Keyboard class provides functionality for getting input data from the physical keyboard. This class is automatically instantiated by and accessible through the InputManager. The Keyboard class is accessible both on a PC as well as on the Xbox 360.
There are many ways to get data from the keyboard. The following section of code is a series of if-statements which could be used to detect input from the keyboard. Add the following using statements:
In your CustomActivity method:
The Keyboard is commonly used to control objects like in-game characters and the Camera. The following code can be used to quickly control any PositionedObject Add the following using statement:
Assuming positionedObject is a valid PositionedObject (or object inheriting from the PositionedObject class like a Sprite or Camera) add the following code in Update:
For more control over input controlling movement, see the following entry on controlling the camera with the keyboard.
The I1DInput interface can be used to generalize input code for detecting a value and velocity along one dimension. A common usage of this is to control objects on one axis such as a platformer character's horizontal movement. Numerous common input devices are implemented as I1DInput. The Value property is typically between -1 and 1.
The following shows how to move an entity horizontally using I1DInput. It assumes that the code has an Entity called Character.
In Character.cs:
In the Screen's CustomInitialize, assuming it has a CharacterInstance:
The following shows examples of I1DInput implementations:
The GetKey function returns an object which can be used to query information about keys. GetKey can be used in situations where the code is written against a general key, or even a general input object, as the return value from GetKey is of type , which implements .
Get2DInput returns an I2DInput instance using the argument keys. This function can be used to abstract input, allowing the same input code to use keyboards and Xbox360GamePad instances. For more information see the page.
The ButtonPushed method returns whether a particular button was pushed. A "push" is defined as occurring when a button is not down the previous frame, but is down the current frame.
The following code might be used to cause an Entity to jump when the A button is pushed:
Alternatively check the ButtonPosition.
The GamepadLayout property returns the type of layout that the Xbox360GamePad returns. This property is set according to the ID and Name reported by the gamepad. Note that this is not always accurate as some manufacturers reuse IDs and Names for different gamepads. If you have a gamepad which is incorrectly reported, please report this in the FlatRedBall chat or create a pull request in the Xbox360GamePad.cs file. Note that the InputManager includes an array of Xbox360GamePad objects for historical and convenience reasons - even controllers which are not Xbox360 (or Xbox One) controllers will appear in this list, such as PlayStation Dual Shock controllers.
The following code could be used to select an icon for a gamepad based on the gamepad layout.
The CreateDefaultButtonMap method is a method which creates a button map for the calling Xbox360GamePad. This is a quick way to bind Keyboard keys to the Xbox360Controller - especially as a fallback during development if an Xbox360 game pad is not connected. For more information on creating custom button maps, see the Xbox360GamePad ButtonMap page.
The CreateDefaultButtonMap method performs the following logic internally:
You can modify the ButtonMap after it's been created:
For more information, see the ButtonMap page.