Class MouseInputComponent

java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.input.InputComponent
com.deco2800.game.components.friendlyunits.MouseInputComponent
All Implemented Interfaces:
com.badlogic.gdx.input.GestureDetector.GestureListener, com.badlogic.gdx.InputProcessor

public class MouseInputComponent extends InputComponent
  • Constructor Details

    • MouseInputComponent

      public MouseInputComponent()
      Controls the input of the mouse, whether it be clicked or clicked and dragged so that when the player does so, a trigger is sent to the Selectable component with the location and type of click movement
  • 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 InputComponent
    • touchDown

      public boolean touchDown(int screenX, int screenY, int pointer, int button)
      Stores value in this class as the starting point of left mouse button being clicked
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDown in class InputComponent
      Parameters:
      screenX - The x coordinate, origin is in the upper left corner
      screenY - The y coordinate, origin is in the upper left corner
      pointer - the pointer for the event.
      button - the button
      Returns:
      See Also:
      • InputProcessor.touchDown(int, int, int, int)
    • mouseMoved

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

      public boolean touchDragged(int screenX, int screenY, int pointer)
      To be completed/doesn't work yet: When mouse is clicked and dragged, a rectangle is drawn to tell you the area of units that will be selected. More of a cosmetic function
      Specified by:
      touchDragged in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDragged in class InputComponent
      Parameters:
      screenX - X-coordinate of the pointer on screen
      screenY - Y-coordinate of the pointer on screen
      pointer - the pointer for the event.
      Returns:
      See Also:
      • InputProcessor.touchDragged(int, int, int)
    • touchUp

      public boolean touchUp(int screenX, int screenY, int pointer, int button)
      handles the finish of the click. If it's a single tap, then we want to select a single unit in out game, if there is an area, then we send this area onto the selectComponent function so that it can determine the units in the area and then select it
      Specified by:
      touchUp in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchUp in class InputComponent
      Parameters:
      screenX - X-coordinate of the pointer on screen
      screenY - Y-coordinate of the pointer on screen
      pointer - the pointer for the event.
      button - the button
      Returns:
      See Also:
      • InputProcessor.touchUp(int, int, int, int)
    • screenToWorldPosition

      public com.badlogic.gdx.math.Vector2 screenToWorldPosition(int screenX, int screenY)
      Converts from screen coordinates to world coordinates, and returns them as a Vector2 (For friendly units).
      Parameters:
      screenX - the x coordinate on the screen
      screenY - the y coordinate on the screen
      Returns:
      the equivalent world coordinates