3 3 GAME INPUT Handling input within games
















- Slides: 16
3. 3. GAME INPUT Handling input within games
QUESTION CLINIC : FAQ In lecture exploration of answers to frequently asked student questions
INPUT DEVICES Different input devices and their use within games
Different input devices There a wide range of different devices used to provide input into games. Some devices are platform specific, e. g. mice are mostly the preserve of PCs, etc. Devices tend to provide different usability profiles and will differ in terms of their suitability to some types of game. A game should best exploit the various input devices it is designed to run with.
Novel forms of input device Input devices need not restrict themselves to the press of a button or movement of some stick (e. g. touch screen, gamepad, driving wheel, joystick). Novel forms of game interface can include: • Distant motion recognition • Speech input • Emotion/thought recognition Bit of fun: You have 5 minutes to come up with an interesting form of gameplay for any of these novel forms of interface. Start 530 4 3 2 Finished 1 mins min sec
Likely input devices… Games on this module will likely use a keyboard, mouse or gamepad controller, from which the following types of input are possible: • • • Pressing a key/button Releasing a key/button (key press+release = typed) Moving the mouse/thumbstick Pressing a mouse button Released a mouse button (press+release = click) Squeezing a trigger Aside: Buttons and keys are examples of 2 -state discrete (on/off, in/out) input. Thumbsticks, mouse location and triggers are examples of ranged input (float/integer return value). To do: Apply to own game
GAME INPUT MECHANISMS Event driven input vs. input polling
Event-driven input vs. Input Polling Event Handler Event-driven input assumes that one, or more, event handlers will handle a defined range of event types. Given an input event, the designated call-back event handler is executed, consuming the event and taking whatever associated action is necessary. Event In contrast, input polling operates by getting the state of the input device Poll a regular sampled intervals and Device checking for change. Most games use input polling. Event Poll Device
Input polling (Advantages and disadvantages) + _ Low level of control, fits well with the frequent update-draw loop in games Input polling provides a snap-shot at an instant in time. Events occurring over a period of time must be inferred from changes in the snap-shots. This includes ‘basic’ events such as a typed key or more sophisticated events such as a mouse drag. Event State Up Time 15 ms 105 ms Typed Pressed +Released Up Down Up 30 ms 45 ms 60 ms 75 ms 90 ms
Input polling (Introductory pitfalls!) update() { if( ‘Launch’ key is pushed down) Launch. Projectile(); } At 60 updates per second, there are some things you do not want to do every update (and maybe only twice per second) Sometimes you might only want to do something once an animation has finished playing: In general: update() { if( input event detected ) if(event execution requirements passed ) Execute. Event() }
Decoupled input Many games support multiple input devices and/or user configurable controls. Within such games it is advantageous to decouple input from input event checking. Decoupling enables input mapping logic to be separated from the code that responds to input events. More generally, decoupling helps promote software extensibility and reusability. update() { Consider. Input() } Consider. Input() { if( ‘A’ button pressed ) Do. Action() } update() { Check. For. Input() Consider. Input() } Check. For. Input() { if( ‘A’ button pressed, or ‘J’ key ) set Jump. Input. Event = true } Consider. Input() { if(Jump. Input. Event == true ) Do. Action() }
LANGUAGE SPECIFIC INPUT Overview of game input using XNA/Java
Input in Java The Java Code Repository makes available a Game. Input. Event. Manager which offers basic keyboard and mouse input (including key/button pressed, new key presses, etc. )
Input in XNA provides Game. Pad, Keyboard and Mouse classes each with a Get. State() method that returns a Game. Pad. State, Keyboard. State or Mouse. State respectively. When using XNA it is common to store the previous input state (from the last update) and compare this against the current input state to detect input event occurrence (e. g. button just pressed, etc. ) Aside: XNA 4. 0 also provides support for touch-screen devices and gestural input
To do: Developing input in your project… In relation to your project, you should: • For each layer, determine the needed user input (e. g. for navigating a menu, or controlling a character, etc. ) • Decide the emphasis that will be placed upon input in your design. Important: Marks will be given for designs that decouple input, enable user customisation, etc. This may be of interest for projects weighting the ‘Extent of game features’ section highly. Balance the implementation cost of this vs. what you hope to achieve in your game. Consider Input
Summary Today we explored: ü Different input devices and their use ü Event driven vs. Input polling ü Project input design consideration : o d o T ge a im e r lo p x e ü Continue ytoand select repositor graphics code e it r w o t e u ü Contin s and displays that load images. sary s e c e n e in m r ü Dete l be il w it w o h d input an implemented