KeyEvents?

Is there no functionality for getting KeyDown/Up messages in XNA? as well as gamepad button down/up messages? If you just get the state of the keyboard once a frame, if the framerate slows the input will become unreliable.
[222 byte] By [Struan] at [2008-3-7]
# 1

There is no event functionaity - you will have to implement it yourself. All you can do is check if something is up or down. See gamepad.cs in spacewar - I had to implement a flag for each button to get indiviudal button presses. It would be easy to turn this into event throwing code.

Yes a slow framerate means you may miss very short presses, but since this is a game its your job to make sure you don't get a slow framerate. Its pretty standard for game programming.

You can probably do something with another thread to make it more responsive if this is a problem.

TheZMan at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 2
Maintaining a high framerate on the XBox is reasonable, but in a windows game where you don't know exactly what hardware will be used people may be running the game at a slower framerate than you expect. Even polling at 30fps will be extremely unreliable, especially for fighting games, where the order buttons are pressed is important (for combos).
Struan at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 3
I'm not so sure a fighting game is going to be terribly playable if the player can't get a good enough framerate, though.
deathy at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 4
Even at 60 frames per second (great framerate). It is still possible to hit a button then a second button within 1/60th of a second and (especially in a fighting game) you can't miss this input (or the order that it was input).
Struan at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 5
You're totally right that some types of fighting game may need input

faster than 1/60 of a second. The best way to do this using XInput

would be to simply poll the gamepad more often, perhaps from a high

priority background thread. This is exactly what all Xbox fighting

games do, because the underlying native API and to the best of my

knowledge even the hardware too is entirely based on polling!

There isn't any event support in the lowest levels of the input reading

system, so you need to poll this at some "fast enough" rate for your

game. For the vast majority of titles, just reading the gamepad once

per frame will work fine.

ShawnHargreaves at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 6
Thats what I was afraid of... oh well. What rate of polling is recommended to be as accurate as possible (i.e. what does the hardware poll at?). Is this something that would be best written as a GameComponent?
Struan at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 7
What kind of game are you writing?

All the commercial games I've ever worked on (mostly racing games and

shooters, on N64, PS2, and Xbox) polled input 60 times a second, and

never had any trouble with that.

I would imagine that a beat-em-up could need to go faster, but having

never written one I don't have a good intuition as to how fast would be

needed.

My advice would be to just ignore the problem until it crops up in

practice. It's the kind of thing where you could spend ages theorizing

about what might go wrong, or just write your game until you actually

see the problems for real, at which point it will be really easy to

experiment and find out exactly what polling rate is needed for good

results!

ShawnHargreaves at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 8
Create a new thread and:

1. Poll input there and fill into buffer
2. Enter a monitor
3. Hand buffer over to main thread
4. Leave monitor
5. Goto 1.

Maybe you can play around with TryEnter in the monitor, and if you can't enter the monitor - just poll even more...

EvilOneSD at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...