I am new to libgdx. I have the following problem. I want to do the scaling for my game. For this, I have a GestureDetectorListener class in my GameStage .
In GameStage , I have the following code for the GestureDetector :
OrthographicCamera camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); this.setCamera(camera); GestureDetector gestureDetector = new GestureDetector(20, 0.5f, 2, 0.15f, new GestureDetectorListener()); Gdx.input.setInputProcessor(gestureDetector); class GestureDetectorListener implements GestureListener { float initialScale = 1; @Override public boolean touchDown(float x, float y, int pointer, int button) { initialScale = camera.zoom; return true; } @Override public boolean tap(float x, float y, int count, int button) { // TODO Auto-generated method stub return true; } @Override public boolean longPress(float x, float y) { // TODO Auto-generated method stub return true; } @Override public boolean fling(float velocityX, float velocityY, int button) { // TODO Auto-generated method stub return true; } @Override public boolean pan(float x, float y, float deltaX, float deltaY) { return true; } @Override public boolean zoom(float initialDistance, float distance) { float ratio = initialDistance / distance; camera.zoom = initialScale * ratio; return true; } @Override public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) { // TODO Auto-generated method stub return true; } }
I also set an InputListener for the Actors of my scene to drag and drop. The problem is that when setting the InputProcessor to the GestureDetector dragging and dropping my Actors does not work. I want to do the zoom using the camera and GestureDetector , but this will not affect the drag and drop. How can i do this?
Any help please! Thanks.
Karmar
source share