Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class InputManager extends InputAdapter {
- private Vector2 lastTouch = new Vector2();
- private Queue<Integer> activeTouch = new Queue<Integer>();
- private boolean xLeft, xRight, yDown, yUp;
- public InputManager() {
- xLeft = false; xRight = false; yDown = false; yUp = false;
- }
- @Override
- public boolean touchDown(int screenX, int screenY, int pointer, int button) {
- activeTouch.addLast(pointer);
- return super.touchDown(screenX, screenY, pointer, button);
- }
- @Override
- public boolean touchUp(int screenX, int screenY, int pointer, int button) {
- if (activeTouch.size > 0) {
- activeTouch.removeValue(pointer, true);
- }
- return super.touchUp(screenX, screenY, pointer, button);
- }
- @Override
- public boolean touchDragged(int screenX, int screenY, int pointer) {
- System.out.println("Dragging:" + pointer + " Queue: " + activeTouch);
- if (pointer == activeTouch.first()) {
- Vector2 newTouch = new Vector2(screenX, screenY);
- Vector2 delta = newTouch.cpy().sub(lastTouch);
- lastTouch = newTouch;
- if (delta.x < 0) {
- xLeft = true;
- xRight = false;
- }
- else if (delta.x > 0) {
- xRight = true;
- xLeft = false;
- }
- else {
- xLeft = false;
- xRight = false;
- }
- if (delta.y < 0) {
- yDown = false;
- yUp = true;
- }
- else if (delta.y > 0) {
- yUp = false;
- yDown = true;
- }
- else {
- yUp = false;
- yDown = false;
- }
- }
- return super.touchDragged(screenX, screenY, pointer);
- }
- public boolean isRightMoved() {
- return xRight;
- }
- public boolean isLeftMoved() {
- return xLeft;
- }
- public boolean isUpMoved() {
- return yUp;
- }
- public boolean isDownMoved() {
- return yDown;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement