Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "COSC 4126 User Interaction User Interaction capturing and responding to input events."— Presentation transcript:

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

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

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

4 COSC 4126 User Interaction Listening for events - interfaces EventListener ...  AWTEventListenerall AWT events  WindowListenerwindow state  KeyListenerkeyboard  MouseListenerclick, press, enter  MouseMotionListenermove, drag  MouseWheelListener

5 COSC 4126 User Interaction 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

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

7 COSC 4126 User Interaction 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

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

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

10 COSC 4126 User Interaction 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.mouseDraggedMouseEvent voidmouseMoved(MouseEvent e) Invoked when the mouse button has been moved on a component (with no buttons down).mouseMovedMouseEvent

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

12 COSC 4126 User Interaction 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

13 COSC 4126 User Interaction User control attaching action to inputs interfaceprogram - game inputaction update point of view point of view: display on/off, tooltips, pan/zoom

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

15 COSC 4126 User Interaction 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

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

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

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

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

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

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


Download ppt "COSC 4126 User Interaction User Interaction capturing and responding to input events."

Similar presentations


Ads by Google