我使用
为了移动摄像机,玩家需要触摸并拖动屏幕。因此,如果您触摸屏幕并向右拖动,则摄像机应该向左移动。就像在画廊中移动缩放图片的部分一样。希望您能明白我的意思。
以下是代码:
我不知道在
感谢您的建议和帮助。
LibGDX
创建了一个2D的Android游戏,并使用正交摄像机在世界中移动。为了移动摄像机,玩家需要触摸并拖动屏幕。因此,如果您触摸屏幕并向右拖动,则摄像机应该向左移动。就像在画廊中移动缩放图片的部分一样。希望您能明白我的意思。
以下是代码:
public class CameraTestMain extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
OrthographicCamera camera;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
camera = new OrthographicCamera(1280, 720);
camera.update();
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
handleInput();
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
public void handleInput() {
// That is my problem
}
}
我不知道在
handleInput()
方法中该写什么。我知道有一个名为InputProcessor
的接口,其中包含方法touchDragged(int x, int y, int pointer)
可以处理触摸拖动,但我不知道如何使用它。感谢您的建议和帮助。
camera.position.set(camera.position.x + screenX, camera.position.y + screenY);
会使相机飞走,因为 screenX 和 screenY 返回鼠标在屏幕上的位置...应该使用某种“X 轴变化”代替 screenX,并对 Y 轴做同样的处理... - Sierox