Class InputComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.input.InputComponent
All Implemented Interfaces:
com.badlogic.gdx.input.GestureDetector.GestureListener, com.badlogic.gdx.InputProcessor
Direct Known Subclasses:
InputDecorator, KeyboardPlayerInputComponent, KeyboardTerminalInputComponent, TouchPlayerInputComponent, TouchTerminalInputComponent

public abstract class InputComponent extends Component implements com.badlogic.gdx.InputProcessor, com.badlogic.gdx.input.GestureDetector.GestureListener
An InputComponent that supports keyboard and touch input and touch gestures. By default an InputComponent does not handle any input events.

Subclasses of InputComponent should override relevant methods to handle input. Ensure the priority is set in the subclass' constructor.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The priority that the input handler is visited in by InputService.

    Fields inherited from class com.deco2800.game.components.Component

    enabled, entity
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Sets priority to the default value;
    protected
    InputComponent(int priority)
    Sets input handler priority to a given value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called when the entity is created and registered.
    void
    Called when the component is disposed.
    boolean
    fling(float velocityX, float velocityY, int button)
     
    int
     
    boolean
    keyDown(int keycode)
     
    boolean
    keyTyped(char character)
     
    boolean
    keyUp(int keycode)
     
    boolean
    longPress(float x, float y)
     
    boolean
    mouseMoved(int screenX, int screenY)
     
    boolean
    pan(float x, float y, float deltaX, float deltaY)
     
    boolean
    panStop(float x, float y, int pointer, int button)
     
    boolean
    pinch(com.badlogic.gdx.math.Vector2 initialPointer1, com.badlogic.gdx.math.Vector2 initialPointer2, com.badlogic.gdx.math.Vector2 pointer1, com.badlogic.gdx.math.Vector2 pointer2)
     
    void
     
    boolean
    Wrapper for pinch stop that can be overridden.
    boolean
    scrolled(float amountX, float amountY)
     
    void
    setPriority(int priority)
     
    boolean
    tap(float x, float y, int count, int button)
     
    boolean
    touchDown(float x, float y, int pointer, int button)
     
    boolean
    touchDown(int screenX, int screenY, int pointer, int button)
     
    boolean
    touchDragged(int screenX, int screenY, int pointer)
     
    boolean
    touchUp(int screenX, int screenY, int pointer, int button)
     
    boolean
    zoom(float initialDistance, float distance)
     

    Methods inherited from class com.deco2800.game.components.Component

    earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • priority

      protected int priority
      The priority that the input handler is visited in by InputService.
  • Constructor Details

    • InputComponent

      protected InputComponent()
      Sets priority to the default value;
    • InputComponent

      protected InputComponent(int priority)
      Sets input handler priority to a given value.
      Parameters:
      priority - input handler's priority
  • Method Details

    • create

      public void create()
      Description copied from class: Component
      Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.
      Overrides:
      create in class Component
    • setPriority

      public void setPriority(int priority)
    • getPriority

      public int getPriority()
    • dispose

      public void dispose()
      Description copied from class: Component
      Called when the component is disposed. Dispose of any internal resources here.
      Overrides:
      dispose in class Component
    • keyDown

      public boolean keyDown(int keycode)
      Specified by:
      keyDown in interface com.badlogic.gdx.InputProcessor
      See Also:
      • InputProcessor.keyDown(int)
    • keyTyped

      public boolean keyTyped(char character)
      Specified by:
      keyTyped in interface com.badlogic.gdx.InputProcessor
      See Also:
      • InputProcessor.keyTyped(char)
    • keyUp

      public boolean keyUp(int keycode)
      Specified by:
      keyUp in interface com.badlogic.gdx.InputProcessor
      See Also:
      • InputProcessor.keyUp(int)
    • mouseMoved

      public boolean mouseMoved(int screenX, int screenY)
      Specified by:
      mouseMoved in interface com.badlogic.gdx.InputProcessor
      See Also:
      • InputProcessor.mouseMoved(int, int)
    • scrolled

      public boolean scrolled(float amountX, float amountY)
      Specified by:
      scrolled in interface com.badlogic.gdx.InputProcessor
      See Also:
      • InputProcessor.scrolled(float, float)
    • touchDown

      public boolean touchDown(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
      See Also:
      • InputProcessor.touchDown(int, int, int, int)
    • touchDragged

      public boolean touchDragged(int screenX, int screenY, int pointer)
      Specified by:
      touchDragged in interface com.badlogic.gdx.InputProcessor
      See Also:
      • InputProcessor.touchDragged(int, int, int)
    • touchUp

      public boolean touchUp(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchUp in interface com.badlogic.gdx.InputProcessor
      See Also:
      • InputProcessor.touchUp(int, int, int, int)
    • fling

      public boolean fling(float velocityX, float velocityY, int button)
      Specified by:
      fling in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.fling(float, float, int)
    • longPress

      public boolean longPress(float x, float y)
      Specified by:
      longPress in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.longPress(float, float)
    • pan

      public boolean pan(float x, float y, float deltaX, float deltaY)
      Specified by:
      pan in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.pan(float, float, float, float)
    • panStop

      public boolean panStop(float x, float y, int pointer, int button)
      Specified by:
      panStop in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.panStop(float, float, int, int)
    • pinch

      public boolean pinch(com.badlogic.gdx.math.Vector2 initialPointer1, com.badlogic.gdx.math.Vector2 initialPointer2, com.badlogic.gdx.math.Vector2 pointer1, com.badlogic.gdx.math.Vector2 pointer2)
      Specified by:
      pinch in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.pinch(Vector2, Vector2, Vector2, Vector2)
    • pinchStop

      public void pinchStop()
      Specified by:
      pinchStop in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.pinchStop()
    • pinchStopHandled

      public boolean pinchStopHandled()
      Wrapper for pinch stop that can be overridden. This was created because the pinchStop() doesn't have a return value.
      Returns:
      whether the input was processed
    • tap

      public boolean tap(float x, float y, int count, int button)
      Specified by:
      tap in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.tap(float, float, int, int)
    • touchDown

      public boolean touchDown(float x, float y, int pointer, int button)
      Specified by:
      touchDown in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.touchDown(float, float, int, int)
    • zoom

      public boolean zoom(float initialDistance, float distance)
      Specified by:
      zoom in interface com.badlogic.gdx.input.GestureDetector.GestureListener
      See Also:
      • GestureDetector.GestureListener.zoom(float, float)