XNA Creators Club Online
Page 1 of 1 (9 items)
Sort Posts: Previous Next

HOW TO avoid your game being failed because of the Guitar controller

Last post 10/14/2009 4:43 PM by PinoEire. 8 replies.
  • 10/14/2009 3:47 PM

    HOW TO avoid your game being failed because of the Guitar controller

    I'd to fail so many good games because of this... so let's see if I can help understanding and solving the problem.

     

    First of all, a little background info. The Guitar controllers have a bad habit: they feed a continuous value to the Right ThumbStick and the Left Trigger. This characteristic causes your game to behave in a very strange way or to be not responsive.

     

    Since Rock Band and Guitar Hero those controllers are widespread and people have them always plugged in so we cannot ignore this issue: it’s not simply because of the Evil Checklist, it’s mostly because you’ll lose a lot of conversions for your potential customer will think that your game is broken!

     

    Let’s assume you have the usual class members:


            private GamePadState[] lastGamePadState = new GamePadState[4];  
            private GamePadState[] currentGamePadState = new GamePadState[4];  

     

    Now all we need is to add this simple method to our input manager:


            public static bool IsAcceptablePad(PlayerIndex index)  
            {  
                return (currentGamePadState[(int)index].IsConnected &&  
                    GamePad.GetCapabilities(index).GamePadType != GamePadType.Guitar &&  
                    GamePad.GetCapabilities(index).GamePadType != GamePadType.AlternateGuitar);  
            } 

    So now all you have to do is to add the result of this method to your code when checking the state of a button, for instance:


            public static bool IsButtonPressedA(PlayerIndex? index, out PlayerIndex ActivePlayer)  
            {  
                PlayerIndex idx;  
                if (index.HasValue)  
                {  
                    idx = (PlayerIndex)index.Value;  
                    ActivePlayer = idx;  
                    return (IsAcceptablePad(idx) &&  
                            inputManager.currentGamePadState[(int)idx].Buttons.A == ButtonState.Pressed &&  
                            inputManager.lastGamePadState[(int)idx].Buttons.A == ButtonState.Released);  
                }  
                else 
                {  
                    return IsButtonPressedA(PlayerIndex.One, out ActivePlayer) ||  
                           IsButtonPressedA(PlayerIndex.Two, out ActivePlayer) ||  
                           IsButtonPressedA(PlayerIndex.Three, out ActivePlayer) ||  
                           IsButtonPressedA(PlayerIndex.Four, out ActivePlayer);  
                }  
            } 

    That’s it folks!

    Cheers,
    Pino




  • 10/14/2009 4:06 PM In reply to

    Re: HOW TO avoid your game being failed because of the Guitar controller

    It might be better to put this on the wiki.  Then push to have a link added to the evil checklist under the multiple controller support fail point.  That way programmers that are actively working through the evil checklist have all the fixes to the evil checklist in one place.
  • 10/14/2009 4:17 PM In reply to

    Re: HOW TO avoid your game being failed because of the Guitar controller

    This is only a problem in 2 situations I have seen:
    1. At the 'Press start' screen people check the triggers/thumbsticks as well as (start) and (A). SImple fix - just check (start) and (A)
    2. Instead of having a (press start) screen they poll ALL controllers during the game and the game relies on triggers/thumsticks. Simple fix - have a press start screen - thats why its in the best practises.

    Feel free to fail games as you find them..

    Also I tweaked the Evil checklist - it already had some words about guitar issues but I added a link to this thread.

    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 10/14/2009 4:18 PM In reply to

    Re: HOW TO avoid your game being failed because of the Guitar controller

    Unless of course you don't mind if someone is playing your game with the guitar ;)  Really if you're checking for an obvious button press like "A" or "Start" there's really no need for this. It's when you do things like check for ANY button press that this becomes an issue. I personally would just encourage developers to be more observant but not to exclude guitar controllers.
  • 10/14/2009 4:21 PM In reply to

    Re: HOW TO avoid your game being failed because of the Guitar controller

    Thanks for this information.  I've been trying to work around this issue, but am unable to test my code since I do not have access to a guitar controller.

    A couple questions:

    PinoEire:
    The Guitar controllers have a bad habit: they feed a continuous value to the Left ThumbStick and the Left Trigger.


    The MSDN  Button Mapping Between Different Controllers and the Xbox 360 Gamepad page says that the Left ThumbStick X-axis, Y-Axis, and button are not used by the guitar controller.  I took this to mean that they would return 0.0f or false.  Is this incorrect?  Do you see non-zero values from the Left ThumbStick X-axis and Y-axis?

    My current workaround is to screen thumbstick inputs from guitar, alternate guitar, and wheel devices in the Input Update method like this:

            public void Update(GameTime gameTime)  
            {  
                totalRealTime = gameTime.TotalRealTime;  
                repeatDelta =   
                    (float)(totalRealTime.TotalSeconds - repeatStart.TotalSeconds);  
     
                for (int i = 0; i < MaxInputs; i++)  
                {  
                    LastKeyboardStates[i] = CurrentKeyboardStates[i];  
                    LastGamePadStates[i] = CurrentGamePadStates[i];  
                    LastLeftStickDirections[i] = CurrentLeftStickDirections[i];  
                    LastRightStickDirections[i] = CurrentRightStickDirections[i];  
     
                    CurrentKeyboardStates[i] = Keyboard.GetState((PlayerIndex)i);  
                    CurrentGamePadStates[i] = GamePad.GetState((PlayerIndex)i);  
     
                    GamePadType padType =  
                        GamePad.GetCapabilities((PlayerIndex)i).GamePadType;  
                    if (padType != GamePadType.Wheel)  
                    {  
                        CurrentLeftStickDirections[i] =  
                            LeftThumbStickDirection((PlayerIndex)i);  
                    }  
                    if (padType != GamePadType.AlternateGuitar &&  
                        padType != GamePadType.Guitar &&  
                        padType != GamePadType.Wheel)  
                    {  
                        CurrentRightStickDirections[i] =  
                            RightThumbStickDirection((PlayerIndex)i);  
                    }  
     
                    // Keep track of whether a gamepad has ever been  
                    // connected, so we can detect if it is unplugged.  
                    if (CurrentGamePadStates[i].IsConnected)  
                    {  
                        GamePadWasConnected[i] = true;  
                    }  
                }  
            } 

    The idea is to allow use of the "well behaved" inputs from all controllers while blocking the problematic inputs from a few controller types.

    Do you think that this approach will work?
    Three colors, endless fun ... Primary Attack
  • 10/14/2009 4:22 PM In reply to

    Re: HOW TO avoid your game being failed because of the Guitar controller

    Yes its the 'right' thumstick.... or is there a profiel way of flipping them for left handed folk?
    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 10/14/2009 4:23 PM In reply to

    Re: HOW TO avoid your game being failed because of the Guitar controller

    Steve Roe:
    The idea is to allow use of the "well behaved" inputs from all controllers while blocking the problematic inputs from a few controller types.

    Do you think that this approach will work?


    I wouldn't make it that complex... detect the controller by having a 'press start' screen that only looks for (start) and (A). Then from that point on only read that controller. If they are dumb enough to start your game with the guitar they deserve everything they get ;-)
    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 10/14/2009 4:29 PM In reply to

    Re: HOW TO avoid your game being failed because of the Guitar controller

    The ZMan:
    Steve Roe:
    The idea is to allow use of the "well behaved" inputs from all controllers while blocking the problematic inputs from a few controller types.

    Do you think that this approach will work?


    I wouldn't make it that complex... detect the controller by having a 'press start' screen that only looks for (start) and (A). Then from that point on only read that controller. If they are dumb enough to start your game with the guitar they deserve everything they get ;-)


    That's how most of the game modes work.  There is one "shared controller" game mode that allows multiple people to play with one or more controllers, so a group of people with one controller could play the game.  The easy way to implement that was to accept input from all controllers.  It seemed like a good idea at the time ...
    Three colors, endless fun ... Primary Attack
  • 10/14/2009 4:43 PM In reply to

    Re: HOW TO avoid your game being failed because of the Guitar controller

    Steve Roe:
    The MSDN  Button Mapping Between Different Controllers and the Xbox 360 Gamepad page says that the Left ThumbStick X-axis, Y-Axis, and button are not used by the guitar controller.  I took this to mean that they would return 0.0f or false.  Is this incorrect?  Do you see non-zero values from the Left ThumbStick X-axis and Y-axis?
    Hi,

    I've mixed left and right, I'll edit the original post! I've checked the Guitars behaviour (using different models) using the Input Reporter sample. This is what is common to the models I tested (leaving the guitar in its default state, not using it):

    Thumbsticks.Right.X = -1
    Thumbsticks.Right.Y = 1
    Triggers.Left = 0.658

    Cheers,
    Pino
Page 1 of 1 (9 items) Previous Next