# GameStateManagement and inputs not being recognized

EDIT: I've removed a bit of code from the input class to make this more readable, and updated my StartScreen class, which is now at the bottom. I have the same issues though, but they are explained in my comments on the bottom of this page. It won't let me paste my additional code here (the format comes out crazy), so I've linked to pastebin with the code pastebin

I've been trying to implement the MS provided GameStateManagement sample with my game, but it has proven a bit difficult. Really, I'm using Oneksoft's Starter Kit, which uses the MS provided sample, so they are identical, except for my splash screen.

I'm able to get the splash screen to launch, where it informs the player to press A to advance the screen, but this doesn't seem to accept any of my inputs. I’ve also added Console.Writeline(“Pressing A”) under the IsMenuPressed method in Input.cs to verify that it is getting called, but for some reason it is constantly spamming my log, rather than just appearing each time I press it. Not sure why this is happening.

I have a bit too much code to post it all here, so I’ve attached a link to my .rar with my classes, but I’ll also leave a bit here which I thinkmay be applicable. https://www.dropbox.com/sh/6ek4uru2jc2ch0k/JTeBWN_3PQ

What do you guys think the issue is?

namespace Pong
{
public class Input
{
public const int MaxInputs = 4;

public readonly KeyboardState[] CurrentKeyboardState;

public KeyboardState[] LastKeyboardState;

public Input()
{
// Get input state
CurrentKeyboardState = new KeyboardState[MaxInputs];

// Preserving last states to check for isKeyUp events
LastKeyboardState = CurrentKeyboardState;
}

/// <summary>
/// Checks for a "menu select" input action.
/// The controllingPlayer parameter specifies which player to read input for.
/// If this is null, it will accept input from any player. When the action
/// is detected, the output playerIndex reports which player pressed it.
/// </summary>
public bool IsMenuSelect(PlayerIndex? controllingPlayer,
out PlayerIndex playerIndex)
{
Console.WriteLine("Pressing A");
return IsNewKeyPress(Keys.Space, controllingPlayer, out playerIndex) ||
IsNewKeyPress(Keys.Enter, controllingPlayer, out playerIndex) ||
IsNewButtonPress(Buttons.A, controllingPlayer, out playerIndex) ||
IsNewButtonPress(Buttons.Start, controllingPlayer, out playerIndex);
}

/// <summary>
/// Checks for a "menu cancel" input action.
/// The controllingPlayer parameter specifies which player to read input for.
/// If this is null, it will accept input from any player. When the action
/// is detected, the output playerIndex reports which player pressed it.
/// </summary>
public bool IsMenuCancel(PlayerIndex? controllingPlayer,
out PlayerIndex playerIndex)
{
return IsNewKeyPress(Keys.Escape, controllingPlayer, out playerIndex) ||
IsNewButtonPress(Buttons.B, controllingPlayer, out playerIndex) ||
IsNewButtonPress(Buttons.Back, controllingPlayer, out playerIndex);
}

• Dave. No one wants to download an unknown rar file. Just paste the code that is related to the issue you're experiencing. Trim out everything that you don't need.
– House
May 15 '12 at 0:14
• You raise a good point. I'm still new to gamedev.stackexchange, so I wasn't sure if that was something people did here or not. Thank you. May 15 '12 at 8:54

Dave your problem is in the PressStartScreen class.

In the constructor it set's up the event handler startMenuEntry.Selected to call the method StartMenuEntrySelected which has no code in it.

You need to add code to this method that will call the main menu or something.

like this :-

namespace Pong
{
class PressStartScreen : MenuScreen
{

public PressStartScreen()
: base("")
{
}

void StartMenuEntrySelected(object sender, PlayerIndexEventArgs e)
{
this.ExitScreen();
}

}
}


Also where you put the "Pressing A" log entry will spam your log because that method is called once every update, and you didn't make it conditional.

Right, checked again and realised that you have :-

public Input()
{
// Get input state
CurrentKeyboardState = new KeyboardState[MaxInputs];

// Preserving last states to check for isKeyUp events
LastKeyboardState = CurrentKeyboardState;
}


which makes LastKeyboardState & LastGamePadState references of CurrentKeyboardState & CurrentGamePadState, change it to :-

public Input()
{
// Get input state
CurrentKeyboardState = new KeyboardState[MaxInputs];

// Preserving last states to check for isKeyUp events
LastKeyboardState = new KeyboardState[MaxInputs];
}

• I'll try this shortly and let you know how this goes May 15 '12 at 8:55
• Sorting through it, you were correct in a number of ways. The pressing A this is resolved now. As far as the StartMenuEntrySelected, I see that I must have removed a call to method called PromptMe() from their, after I went back to compare it to the Oneksoft's. I realized that I did that because the method integrated Nick Gravelyn's Easy Storage, which I didn't know how to add to my project at the time. It has since been added, and I've added the method, but still no dice :// May 15 '12 at 10:20

If the point is to preserve the last game state, wouldn't it make sense to reverse the order of these:

public Input()
{
// Get input state
CurrentKeyboardState = new KeyboardState[MaxInputs];

// Preserving last states to check for isKeyUp events
LastKeyboardState = CurrentKeyboardState;
}


So that the CurrentState gets passed off to Last State, and then updated? It should look something like this:

public Input()
{
// Preserving last states to check for isKeyUp events
LastKeyboardState = CurrentKeyboardState;