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 TypeMethodDescriptionvoidcreate()Called when the entity is created and registered.booleanmouseMoved(int screenX, int screenY) com.badlogic.gdx.math.Vector2screenToWorldPosition(int screenX, int screenY) Converts from screen coordinates to world coordinates, and returns them as a Vector2 (For friendly units).booleantouchDown(int screenX, int screenY, int pointer, int button) Stores value in this class as the starting point of left mouse button being clickedbooleantouchDragged(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.booleantouchUp(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, zoomMethods 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:ComponentCalled 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:
createin 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:
touchDownin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDownin 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:
mouseMovedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
mouseMovedin 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:
touchDraggedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDraggedin 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:
touchUpin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchUpin 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
-