我是 libgdx 的新手。我有以下问题。我想为我的游戏做捏缩放。为此,我GestureDetectorListener
在我的GameStage
.
在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
,我的演员的拖动不起作用。我想用相机和 进行捏缩放GestureDetector
,但它不会对拖动产生影响。我怎样才能做到这一点?
请提供任何帮助!谢谢。