@Override
public void create () {
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
batch = new SpriteBatch();
img = new Texture("asd.jpg");
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isTouched()){
camera.position.x = Gdx.input.getX();
camera.position.y = Gdx.input.getY();
}
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
这也是我尝试做的,但它不能稳定运行。
if(Gdx.input.isTouched()){
if(!nowOn){
asd.x = camera.position.x + Gdx.input.getX() * -1;
asd.y = camera.position.y + Gdx.input.getY();
camera.position.x = asd.x;
camera.position.y = asd.y;
}
}else{
if(nowOn){
nowOn = false;
asd.x = Gdx.input.getX() + camera.position.x;
asd.y = Gdx.input.getY() + camera.position.y;
}
}
我可以使用此代码在屏幕上移动相机,但我希望我会用手指移动相机,然后我将释放我的手指,在我重新触摸屏幕后,我将继续移动相机停留的位置。
总结一下,我想用手指漫游大图像。
感谢:)