1 / 21

User Interaction

User Interaction. capturing and responding to input events. Event handling in java. JRE. user action. input device. OS. AWT event queue. component + event. component event listeners. Events – message passing. AWTEvent ... ComponentEvent ... InputEvent KeyEvent MouseEvent ...

yuli-avery
Télécharger la présentation

User Interaction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. User Interaction capturing and responding to input events COSC 4126 User Interaction

  2. Event handling in java JRE user action input device OS AWT event queue component + event component event listeners COSC 4126 User Interaction

  3. Events – message passing AWTEvent • ... • ComponentEvent • ... • InputEvent • KeyEvent • MouseEvent • ... • MouseWheelEvent COSC 4126 User Interaction

  4. Listening for events - interfaces EventListener • ... • AWTEventListener all AWT events • WindowListener window state • KeyListener keyboard • MouseListener click, press, enter • MouseMotionListener move, drag • MouseWheelListener COSC 4126 User Interaction

  5. constructing a listener • create component object to capture events (window, button, etc) • create object that implements listener interface • code for reacting to event • attach listener to component COSC 4126 User Interaction

  6. Keyboard control KeyListener methods public void keyTyped(KeyEvent e) Invoked when a key has been typed. See the class description for KeyEvent for a definition of a key typed event. (not often used in a real-time situation – includes multi-key combinations as single events) public void keyPressed(KeyEvent e) Invoked when a key has been pressed. See the class description for KeyEvent for a definition of a key pressed event. public void keyReleased(KeyEvent e) Invoked when a key has been released. See the class description for KeyEvent for a definition of a key released event. COSC 4126 User Interaction

  7. Keyboard control KeyEvent contains information about the event what character, key location (eg left/right shift) multiple formats, string, unicode, ... for games, typically a small set of key actions are used for game control; other key events are ignored; note details in Brackeen (e.g., disabling tabs and alts) example: KeyTest.java in chapter 3 COSC 4126 User Interaction

  8. Mouse control • MouseListener void mouseClicked(MouseEvent e)           Invoked when the mouse button has been clicked (pressed and released) on a component. void mouseEntered(MouseEvent e)           Invoked when the mouse enters a component. void mouseExited(MouseEvent e)           Invoked when the mouse exits a component. for game interaction void mousePressed(MouseEvent e)           Invoked when a mouse button has been pressed on a component. void mouseReleased(MouseEvent e)           Invoked when a mouse button has been released on a component. COSC 4126 User Interaction

  9. Mouse control • MouseEvent • which button is pressed, released • mouse location COSC 4126 User Interaction

  10. Mouse control • MouseMotionListener voidmouseDragged(MouseEvent e)           Invoked when a mouse button is pressed on a component and then dragged. All dragged events go to component where button was pushed. voidmouseMoved(MouseEvent e)           Invoked when the mouse button has been moved on a component (with no buttons down). COSC 4126 User Interaction

  11. Mouse control • MouseWheelListener void mouseWheelMoved(MouseWheelEvent e)           Invoked when the mouse wheel is rotated. MouseWheelEvent extends MouseEvent • number of clicks (pos or neg) • number of scroll units • scroll type ( by line or by page ) example: MouseTest.java COSC 4126 User Interaction

  12. The user input “language” • keyReleased(key) • mousePressed(button), mouseReleased(button) • keyPressed(key) • mouseMoved, mouseDragged • mouseWheelMoved change of state single action possible multiple or continuous action COSC 4126 User Interaction

  13. User controlattaching action to inputs interface program - game input action point of view update point of view: display on/off, tooltips, pan/zoom COSC 4126 User Interaction

  14. Mouselook – panning the view draw fullscreen image four times at: (x,y) (x-w,y) (x,y-h) (x-w,y-h) (x,y) COSC 4126 User Interaction

  15. Mouselook – Panning with mouse • mouseMoved event • calculate change in mouse position • apply change to image display point (x,y) • reset mouse to screen centre example: MouselookTest.java COSC 4126 User Interaction

  16. Robot classcontrolling mouse and keys void keyPress(int keycode)   Presses a given key. void keyRelease(int keycode)   Releases a given key. void mouseMove(int x, int y)   Moves mouse pointer to given screen coordinates. void mousePress(int buttons)   Presses one or more mouse buttons. void mouseRelease(int buttons) Releases one or more mouse buttons. void mouseWheel(int wheelAmt)   Rotates the scroll wheel on wheel-equipped mice. ... other methods COSC 4126 User Interaction

  17. Brackeen’s Input Manager • capture input Events • manage Event interpretation • manage connection of Events to GameActions • control when GameActions are made COSC 4126 User Interaction

  18. InputManager class keyActions gameActions listeners 1 - 1 update game state mouseActions remapped COSC 4126 User Interaction

  19. InputManagerTest example keys space A D   P <esc> mouse MOUSEBUTTON1 MOUSEMOVELEFT MOUSEMOVERIGHT game actions moveLeft moveRight jump pause exit events keyPressed keyReleased mousePressed mouseReleased mouseMoved COSC 4126 User Interaction

  20. Player class • moveLeft, moveRight, jump effect sprite • Player extends Sprite class • state: jumping or normal • floor: y-coordinate of normal path vertical velocity set by jump ‘falls’ over time 0 jump event COSC 4126 User Interaction

  21. Assignments: • first individual assignment – one week • two interfaces • second group assignment – Thursday • topic • document – team plus topic COSC 4126 User Interaction

More Related