GameStateManagement and inputs not being recognized
Posted
by
Dave Voyles
on Game Development
See other posts from Game Development
or by Dave Voyles
Published on 2012-05-14T23:42:39Z
Indexed on
2012/06/07
16:48 UTC
Read the original article
Hit count: 237
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 readonly GamePadState[] CurrentGamePadState;
public KeyboardState[] LastKeyboardState;
public GamePadState[] LastGamePadState;
public readonly bool[] GamePadWasConnected;
public Input()
{
// Get input state
CurrentKeyboardState = new KeyboardState[MaxInputs];
CurrentGamePadState = new GamePadState[MaxInputs];
// Preserving last states to check for isKeyUp events
LastKeyboardState = CurrentKeyboardState;
LastGamePadState = CurrentGamePadState;
}
/// <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);
}
© Game Development or respective owner