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
-
Field Summary
Fields inherited from class com.deco2800.game.input.InputComponent
priority
-
Constructor Summary
ConstructorsConstructorDescriptionControls 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 Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.boolean
mouseMoved
(int screenX, int screenY) 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).boolean
touchDown
(int screenX, int screenY, int pointer, int button) Stores value in this class as the starting point of left mouse button being clickedboolean
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.boolean
touchUp
(int screenX, int screenY, int pointer, int button) handles the finish of the click.Methods inherited from class com.deco2800.game.input.InputComponent
dispose, fling, getPriority, keyDown, keyTyped, keyUp, longPress, pan, panStop, pinch, pinchStop, pinchStopHandled, scrolled, setPriority, tap, touchDown, zoom
Methods inherited from class com.deco2800.game.components.Component
earlyUpdate, getEntity, isAnimationRenderComponent, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
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 classInputComponent
-
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 interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDown
in classInputComponent
- Parameters:
screenX
- The x coordinate, origin is in the upper left cornerscreenY
- The y coordinate, origin is in the upper left cornerpointer
- 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 interfacecom.badlogic.gdx.InputProcessor
- Overrides:
mouseMoved
in classInputComponent
- 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 interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDragged
in classInputComponent
- Parameters:
screenX
- X-coordinate of the pointer on screenscreenY
- Y-coordinate of the pointer on screenpointer
- 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 interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchUp
in classInputComponent
- Parameters:
screenX
- X-coordinate of the pointer on screenscreenY
- Y-coordinate of the pointer on screenpointer
- 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 screenscreenY
- the y coordinate on the screen- Returns:
- the equivalent world coordinates
-