The ControlMapping is kind of a mix of the other possibilities to obtain input data. By using the ControlMapping you are able to create your own controllers like this:

    public class BasicArcadeControl
    {
        DigitalOneShotControl pauseControl;
        DigitalOneShotControl fireControl;
        DigitalOneShotControl jumpControl;
        DigitalInvertableDirectionControl moveControl;

        public Boolean Pause
        {
            get { return pauseControl.Pressed; }
        }

        public Boolean Fire
        {
            get { return fireControl.Pressed; }
        }

        public Boolean Jump
        {
            get { return jumpControl.Pressed; }
        }

        public Boolean Left
        {
            get { return moveControl.Left; }
        }

        public Boolean Right
        {
            get { return moveControl.Right; }
        }

        public Boolean Up
        {
            get { return moveControl.Up; }
        }

        public Boolean Down
        {
            get { return moveControl.Down; }
        }

        public BasicArcadeControl(DigitalOneShotControl pauseControl,
                                  DigitalOneShotControl fireControl,
                                  DigitalOneShotControl jumpControl,
                                  DigitalInvertableDirectionControl moveControl)
        {
            this.pauseControl = pauseControl;
            this.fireControl = fireControl;
            this.jumpControl = jumpControl;
            this.moveControl = moveControl;
        }
    }

By calling the constructor with controls obtained by the InputManager's getInputDevice method you will get a class managing basic arcade inputs of a digital gamepad. Easy, isn't it?

You can easily change the behavior of your class by tuning the properties. If you want some kind of auto fire you could change the .Pressed property to .Held and you will have continuous fire on every update not only on the first button press.

Another advantage is, that you easily can switch to other controls. You can use keyboard keys on windows for example and a digital gamepad on the XBox or on windows if the user has connected one.

Last edited Dec 15, 2010 at 7:43 AM by Glatzemann, version 1

Comments

No comments yet.