User Interaction

Download User Interaction

Post on 01-Jan-2016

15 views

Category:

Documents

1 download

Embed Size (px)

DESCRIPTION

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 ... - PowerPoint PPT Presentation

TRANSCRIPT

  • User Interactioncapturing and respondingtoinput events

    COSC 4126 User Interaction

  • Event handling in javauser actioninput deviceOSJREAWT event queuecomponent event listenerscomponent+ event

    COSC 4126 User Interaction

  • Events message passingAWTEvent...ComponentEvent...InputEventKeyEventMouseEvent...MouseWheelEvent

    COSC 4126 User Interaction

  • Listening for events - interfacesEventListener...AWTEventListenerall AWT eventsWindowListenerwindow stateKeyListenerkeyboardMouseListenerclick, press, enterMouseMotionListenermove, dragMouseWheelListener

    COSC 4126 User Interaction

  • constructing a listenercreate component object to capture events (window, button, etc)create object that implements listener interfacecode for reacting to eventattach listener to component

    COSC 4126 User Interaction

  • Keyboard controlKeyListener methodspublic void keyTyped(KeyEvente) 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(KeyEvente) Invoked when a key has been pressed. See the class description for KeyEvent for a definition of a key pressed event.

    public void keyReleased(KeyEvente) 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

  • Keyboard controlKeyEventcontains information about the eventwhat 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

  • Mouse controlMouseListenervoid mouseClicked(MouseEvente) Invoked when the mouse button has been clicked (pressed and released) on a component.void mouseEntered(MouseEvente) Invoked when the mouse enters a component.void mouseExited(MouseEvente) Invoked when the mouse exits a component.for game interactionvoid mousePressed(MouseEvente) Invoked when a mouse button has been pressed on a component.void mouseReleased(MouseEvente) Invoked when a mouse button has been released on a component.

    COSC 4126 User Interaction

  • Mouse controlMouseEventwhich button is pressed, releasedmouse location

    COSC 4126 User Interaction

  • Mouse controlMouseMotionListenervoidmouseDragged(MouseEvente) Invoked when a mouse button is pressed on a component and then dragged. All dragged events go to component where button was pushed.voidmouseMoved(MouseEvente) Invoked when the mouse button has been moved on a component (with no buttons down).

    COSC 4126 User Interaction

  • Mouse controlMouseWheelListenervoid mouseWheelMoved(MouseWheelEvente) Invoked when the mouse wheel is rotated.MouseWheelEvent extends MouseEventnumber of clicks (pos or neg)number of scroll unitsscroll type ( by line or by page )

    example: MouseTest.java

    COSC 4126 User Interaction

  • The user input languagekeyReleased(key)mousePressed(button),mouseReleased(button)

    keyPressed(key)

    mouseMoved, mouseDraggedmouseWheelMovedchange of statesingle actionpossible multiple or continuous action

    COSC 4126 User Interaction

  • User controlattaching action to inputsinterfaceprogram - gameinputactionupdatepoint of viewpoint of view:display on/off, tooltips, pan/zoom

    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)

    COSC 4126 User Interaction

  • Mouselook Panning with mousemouseMoved eventcalculate change in mouse positionapply change to image display point (x,y)reset mouse to screen centre

    example: MouselookTest.java

    COSC 4126 User Interaction

  • Robot classcontrolling mouse and keysvoid keyPress(intkeycode) Presses a given key.void keyRelease(intkeycode) Releases a given key.void mouseMove(intx, inty) Moves mouse pointer to given screen coordinates.void mousePress(intbuttons) Presses one or more mouse buttons.void mouseRelease(intbuttons) Releases one or more mouse buttons.void mouseWheel(intwheelAmt) Rotates the scroll wheel on wheel-equipped mice.... other methods

    COSC 4126 User Interaction

  • Brackeens Input Managercapture input Events manage Event interpretationmanage connection of Events to GameActionscontrol when GameActions are made

    COSC 4126 User Interaction

  • InputManager class keyActionsmouseActionsgameActionsupdate game statelisteners1 - 1remapped

    COSC 4126 User Interaction

  • InputManagerTest examplegame actionsmoveLeftmoveRightjumppauseexitkeysspaceADP

    mouseMOUSEBUTTON1MOUSEMOVELEFTMOUSEMOVERIGHTeventskeyPressedkeyReleasedmousePressedmouseReleasedmouseMoved

    COSC 4126 User Interaction

  • Player classmoveLeft, moveRight, jump effect spritePlayer extends Sprite classstate: jumping or normalfloor: y-coordinate of normal pathvertical velocityset by jumpfalls over time0jump event

    COSC 4126 User Interaction

  • Assignments:first individual assignment one weektwo interfacessecond group assignment Thursdaytopicdocument team plus topic

    COSC 4126 User Interaction

Recommended

View more >