libgdx ゲームにタッチ スクロールを実装しようとしています。部屋のパノラマであるワイド画像があります。ユーザーが部屋の周りを見ることができるように、画像をスクロールできるようにしたい。一定の距離をスクロールできるようにしていますが、新しい touchDragged イベントが登録されると、画像は元の位置に戻ります。
これが私がそれを実装している方法です
public class AttackGame implements ApplicationListener {
AttackInputProcessor inputProcessor;
Texture backgroundTexture;
TextureRegion region;
OrthographicCamera cam;
SpriteBatch batch;
float width;
float height;
float posX;
float posY;
@Override
public void create() {
posX = 0;
posY = 0;
width = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight();
backgroundTexture = new Texture("data/pancellar.jpg");
region = new TextureRegion(backgroundTexture, 0, 0, width, height);
batch = new SpriteBatch();
}
@Override
public void resize(int width, int height) {
cam = new OrthographicCamera();
cam.setToOrtho(false, width, height);
cam.translate(width / 2, height / 2, 0);
inputProcessor = new AttackInputProcessor(width, height, cam);
Gdx.input.setInputProcessor(inputProcessor);
}
@Override
public void render() {
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
batch.setProjectionMatrix(cam.combined);
batch.begin();
batch.draw(backgroundTexture, 0, 0, 2400, 460);
batch.end();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
backgroundTexture.dispose();
}
}
そしてInputProcessorで
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
cam.position.set(screenX, posY / 2, 0);
cam.update();
return false;
}
この質問LibGdx How to Scroll using OrthographicCamera?の助けを借りて、ここまで来ました。. しかし、それは私の問題を本当に解決しません。
問題は touchDragged corodinates がワールド座標ではないことにあると思いますが、カメラの投影を解除しようとしましたが、効果はありませんでした。
私はこれに数週間苦労しており、これについて何か助けていただければ幸いです.
前もって感謝します。