package com.fainted.phase.editor.ui;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
public class GlobalControls implements InputProcessor {
private static boolean cameraTranslate;
private Vector2 cameraTranslateVec;
public GlobalControls() {
cameraTranslateVec = new Vector2();
}
public void update(Camera camera) {
if(cameraTranslate == true) {
camera.translate(MathUtils.clamp(cameraTranslateVec.x, -8f, 8f), MathUtils.clamp(-cameraTranslateVec.y, -8f, 8f), 0);
}
if(Gdx.input.isKeyPressed(Keys.S)) {
cameraTranslate = true;
} else {
cameraTranslate = false;
cameraTranslateVec.x = 0;
cameraTranslateVec.y = 0;
}
}
@Override
public boolean keyDown(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyUp(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
cameraTranslateVec.x = (Gdx.input.getX() - Gdx.graphics.getWidth()/2) / 40;
cameraTranslateVec.y = (Gdx.input.getY() - Gdx.graphics.getHeight()/2) / 40;
return false;
}
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
cameraTranslateVec.x = 0;
cameraTranslateVec.y = 0;
return false;
}
@Override
public boolean touchDragged(int x, int y, int pointer) {
cameraTranslateVec.x = (Gdx.input.getX() - Gdx.graphics.getWidth()/2) / 40;
cameraTranslateVec.y = (Gdx.input.getY() - Gdx.graphics.getHeight()/2) / 40;
return false;
}
@Override
public boolean touchMoved(int x, int y) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean scrolled(int amount) {
// TODO Auto-generated method stub
return false;
}
}