I1DInput

Introduction

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.

Code Example

The following shows how to move an entity horizontally using I1DInput. It assumes that the code has an Entity called Character.

In Character.cs:

using FlatRedBall.Input;

namespace ProjectName.Entities
{
    public partial class Character
    {
        public I1DInput HorizontalInput
        {
            get;
            set;
        }

        private void CustomInitialize()
        {
        }

        private void CustomActivity()
        {
            // This would normally be a Glue variable, but added
            // here to keep the example simpler
            float movementSpeed = 100;
            this.XVelocity = HorizontalInput.Value * movementSpeed;
        }

        private void CustomDestroy()
        {
        }

        private static void CustomLoadStaticContent(string contentManagerName)
        {
        }
    }
}

In the Screen's CustomInitialize, assuming it has a CharacterInstance:

Common Usage

The following shows examples of I1DInput implementations:

Last updated

Was this helpful?