我是libgdx的新手,我遇到了以下问题。我想为我的游戏实现捏合缩放功能。为此,我在我的GameStage中有一个GestureDetectorListener类。
在GameStage中,我有以下代码用于GestureDetector:
我在我的舞台上为演员设置了InputListener,以便拖动它们。问题是,当我将InputProcessor设置为GestureDetector时,我的Actors的拖动不起作用。我想使用相机和GestureDetector进行捏合缩放,但这不会影响拖动。我该怎么做?
请帮忙!谢谢。
在GameStage中,我有以下代码用于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;
}
}
我在我的舞台上为演员设置了InputListener,以便拖动它们。问题是,当我将InputProcessor设置为GestureDetector时,我的Actors的拖动不起作用。我想使用相机和GestureDetector进行捏合缩放,但这不会影响拖动。我该怎么做?
请帮忙!谢谢。