I'm creating a method that moves a sprite across the screen depending on what key is pressed
class InputController
{
public void DetectInput (Vector2 position)
{
if (Keyboard.GetState().IsKeyDown(Keys.W))
{
position.Y -= 1;
}
if (Keyboard.GetState().IsKeyDown(Keys.S))
{
position.Y += 1;
}
if (Keyboard.GetState().IsKeyDown(Keys.A))
{
position.X -= 1;
}
if (Keyboard.GetState().IsKeyDown(Keys.D))
{
position.X += 1;
}
Trying to call if from my other class, I get an error:
System.NullReferenceException: 'Object reference not set to an instance of an object
InputController was null
Here is the relevant code from the other class
private InputController InputController;
protected override void Update(GameTime gameTime)
{
InputController.DetectInput(_position);
}