Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
}
share|improve this question
1  
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. –  Byte56 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. –  Dave Voyles May 15 '12 at 8:54
add comment

2 Answers

up vote 1 down vote accepted

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("")
        {
            MenuEntry startMenuEntry = new MenuEntry("Press A to start");
            startMenuEntry.Selected += StartMenuEntrySelected;
            MenuEntries.Add(startMenuEntry);
        }

        void StartMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            this.ScreenManager.AddScreen(new MainMenuScreen(), e.PlayerIndex);
            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];
    CurrentGamePadState = new GamePadState[MaxInputs];

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

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

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

    // Preserving last states to check for isKeyUp events
    LastKeyboardState = new KeyboardState[MaxInputs];
    LastGamePadState = new GamePadState[MaxInputs];
}
share|improve this answer
    
I'll try this shortly and let you know how this goes –  Dave Voyles 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 :// –  Dave Voyles May 15 '12 at 10:20
    
Brilliant! It worked! Thank you –  Dave Voyles May 15 '12 at 15:24
add comment

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];
    CurrentGamePadState = new GamePadState[MaxInputs];

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

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;
        LastGamePadState = CurrentGamePadState;

        // Get New Input State
        CurrentKeyboardState = new KeyboardState[MaxInputs];
        CurrentGamePadState = new GamePadState[MaxInputs];
    }
share|improve this answer
    
+1 Yes. Yes, this is how previous state storage operations should generally go. –  Jonathan Hobbs Jun 7 '12 at 15:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.