Re: Questions about C#
@21, your thinking in a more BGT-ish way of doing things. You need to get out of that mindset -- its not going to help you here.
Windows forms (and every other kind of UI library) rely on events to convey information to you. There is no central "key_pressed" function because that's not how a UI actually works. Even game frameworks like SDL2 and SFML do not function this way. I've no doubt that its safe to say that BGT has taught you the entirely wrong way of doing things. Which is why I keep emphasizing that we need to get rid of duplicating BGT idioms in other languages -- it breaks the underlying model of game design. A game fundamentally works off of events, not off of you constantly polling the system. Same for UIs and pretty much everything else. Asynchronous programming -- which is what this is -- is far better than endlessly polling the system for information. SDL2 and such may handle this asynchronous stuff for you so you can poll them as usual, but underneath this is what they're doing. In Winforms and such, though, you don't have SDL2/SFML to make your life all easy-peacy. And you shouldn't have them. Winforms and such is how GUI design works.
To handle keyboard events in windows forms, create a function to handle all keyboard events:
private void Form_KeyDown(Object sender, KeyEventArgs e) {
// Handle key down events here
switch (e.KeyCode) {
case Keys.A:
// Handle...
break;
// ...
}
}
You will also want to define keyboard events for key presses (the KeyPress event), key releases (the KeyUp event) and, optionally, the KeyUp event.
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector