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

Which would you prefer....?

Last post 01-28-2008 3:38 PM by ShawMishrak. 10 replies.
  • 01-27-2008 11:26 PM

    Which would you prefer....?

    We're working on an engine right now (QuickStart Engine), and we've come across a simple question and would like your guys' input on it.

    If you were using an input manager for controls for your video game, which would you prefer as an easy-to-understand button naming convention? Basically, which of the following schemes makes the most sense to you? And in your response if you could give a small comment on why it was the easiest to understand. And finally, if you think you've got a better one, feel free to post your suggestion. Thanks guys.

    Method 1:
    "ButtonUp": For buttons that are up.
    "ButtonDown": For buttons that are down.
    "ButtonPressed": For buttons that are down for more than 1 frame (being held down or pressed for a period of time).

    Method 2:
    "ButtonUp": For buttons that are up.
    "ButtonDown": For buttons that are down.
    "ButtonHeld": For buttons that are down for more than 1 frame (being held down or pressed for a period of time).

    Method 3:
    "ButtonReleased": For buttons that are up.
    "ButtonPressed": For buttons that are down.
    "ButtonHeld": For buttons that are down for more than 1 frame (being held down or pressed for a period of time).

    XNA QuickStart Engine | My site
    "I'll be whatever I want to do!", Philip J. Fry
  • 01-27-2008 11:41 PM In reply to

    Re: Which would you prefer....?

    I'd cast my vote for method #2 simply because I prefer the language "button held".

    Joel Martinez - XNA MVP  
    Blog: http://codecube.net
    Play Videos on an XNA Texture: Scurvy Media
    XNA Unit Testing: Scurvy Test
  • 01-27-2008 11:44 PM In reply to

    Re: Which would you prefer....?

    For those event descriptions I would go with #2. Reason being that the ButtonPressed event is relateable to the KeyPressed event in WinForms which is caused by a button being pressed and then released. So to ease confusion I would go with #2.
  • 01-28-2008 6:37 AM In reply to

    Re: Which would you prefer....?

    Based on your descriptions #2 makes the most sense to me.  The third option makes it seem like you're checking for a button event like it was just pressed or released
    http://www.freewebs.com/campelmxna/ - C# and XNA tutorials
    The only stupid mistake is the one you make twice
  • 01-28-2008 7:35 AM In reply to

    Re: Which would you prefer....?

    For naming conventions from your descriptions I'd say method 2 makes more sence.  Pressed and Released sound the button has just been pressed or released on that frame, so that's a little misleading based on your descriptions.  I also think that the functionality of the ButtonHeld is rather pointless since it's basicly going to provide the same information as ButtonDown with the exception that it won't report buttons that were only pressed this frame causing a one frame delay on any input using this command.

    Personally for my own projects I have something similar to:
    ButtonUp:           Buttons that are up
    ButtonDown:       Buttons that are down
    ButtonPressed:    Buttons pressed this frame
    ButtonReleased:   Buttons released this frame

    Seems to cover anything I need.
  • 01-28-2008 7:37 AM In reply to

    Re: Which would you prefer....?

    Hmm, I would have been tempted by #3, given its most similar to the ButtonState.xxx enum that you'd use via GamePadState...

    But then I guess this is meant to sit about that, and include keyboard input too.

    Muzz http://www.PositronicArts.com/blog
  • 01-28-2008 8:54 AM In reply to

    Re: Which would you prefer....?

    ButtonUp = Single event for button transition from down to up.

    ButtonDown = Single event for button transition from up to down.

    ButtonPressed = Continuous events for buttons that are down.

    ButtonHeld = Continous events for buttons that are down for longer then a configurable time threshhold. 

    http://www.robotechmmo.com
  • 01-28-2008 9:54 AM In reply to

    Re: Which would you prefer....?

    Kafeen:
    For naming conventions from your descriptions I'd say method 2 makes more sence.  Pressed and Released sound the button has just been pressed or released on that frame, so that's a little misleading based on your descriptions.  I also think that the functionality of the ButtonHeld is rather pointless since it's basicly going to provide the same information as ButtonDown with the exception that it won't report buttons that were only pressed this frame causing a one frame delay on any input using this command.

    Sending messages whenever a button is held allows you to perform actions that will occur only when a button is held. One thing I've run into in the past is a camera that moves whenever you hold in a mouse button (similar to World of Warcraft), but whenever you click a single or double mouse click you wouldn't want the camera reacting because you're likely interacting with UI.

    XNA QuickStart Engine | My site
    "I'll be whatever I want to do!", Philip J. Fry
  • 01-28-2008 12:07 PM In reply to

    Re: Which would you prefer....?

    I'd do with Method2 as well.  I think the naming conventions are more descriptive of the controller state.   I would want the threshold between Down and Held to be configurable.

    Do these come as messages (a la Windows WM_LBUTTONDOWN), or as state passed to an update call (i.e. a replacement for MouseState)? 

    --------------------
    John H
    www.kestudios.com
  • 01-28-2008 1:29 PM In reply to

    Re: Which would you prefer....?

    The messages will be coming through the engines message handler via custom messages, and will be for mouse, keyboard, and gamepad.
    XNA QuickStart Engine | My site
    "I'll be whatever I want to do!", Philip J. Fry
  • 01-28-2008 3:38 PM In reply to

    Re: Which would you prefer....?

    Perhaps this is another issue where feedback would be very useful.

    Currently, the input state information is propogated around the engine as messages, as LordIkon has stated.  This is a global event subscribable by all engine systems.  Every time the input system detects input state changes, this event handler is called with appropriate event types.  The system is very similar to the Windows message pump, with the exception of message types being derived classes from a common interface type.  Engine-level code would see something like:

    public void MyMessageHandler(IMessage msg)
    {
    // Process message type and perform appropriate logic
    }

    To game code, this approach may become somewhat messy.  However, this abstraction seems necessary to decouple the internal engine systems.  To accomodate a more clean interface for game-level code, an input mapper will be created.  This mapper will subscribe to and process input events, along with an internal key/button -> event name mapping, and maintain internal states.  Game-level code will then be able to make calls like:

    public void Update(GameTime gameTime)
    {
    if(inputMapper.IsEventActive(MyEvents.MoveForward)) // Key/button bound to "MoveForward" is being pressed/held.
    {
    }

    if(inputMapper.IsEventJustFired(MyEvents.MenuItemActivate)) // Key/button bound to "MenuItemActivate" was just pressed this frame.
    {
    }
    }


    Clearly, input control is just one use of the messaging system.

    Comments?
    Microsoft DirectX/XNA MVP
Page 1 of 1 (11 items) Previous Next