【发布时间】:2017-05-27 00:52:17
【问题描述】:
我试图让鼠标单击 + 拖动导致正交相机相对于初始单击移动。
下面的内容几乎是我想要的。
但是,您可以看出,当我点击圣马特奥大桥以南的蓝色区域时,相机会跳转到一个奇怪的位置,然后才能让相机在整个拖动过程中平稳移动。
当前对相机的所有操作都是通过具有 InputProcessor 接口的类完成的。
处理相机拖动的方法有#touchDown和#touchDragged。 #touchDragged 考虑了由#scrolled 操作的地图的缩放。
/**
* Sets values at which mouse initially clicked to be used for moving the camera about
*
* @param screenX - The x coordinate, origin is in the upper left corner
* @param screenY - The y coordinate, origin is in the upper left corner
* @param pointer
* @param button
* @return
*/
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (button != 0) return false;
pressedX = screenX;
pressedY = screenY;
return false;
}
/**
* In the event of a drag, the camera position is altered to correspond to a drag relative to the initial click
*
* @param screenX - The x coordinate, origin is in the upper left corner
* @param screenY - The y coordinate, origin is in the upper left corner
* @param pointer
* @return
*/
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
final float zoomMultiplier = camera.zoom / 20f;
camera.position.set(map.getWidth() - screenX * zoomMultiplier, screenY * zoomMultiplier, 0);
return false;
}
/**
* Zooms into or out of the map based on which direction the user scrolls
* @param amount - The intensity of the scroll
* @return
*/
@Override
public boolean scrolled(int amount) {
final float zoomAmount = amount * 1.15f;
camera.zoom += zoomAmount;
return false;
}
缩放似乎不会影响拖动动作的正确性,因为它已被考虑在内。但是,初始点击似乎没有按预期工作,因为它的初始跳转并跳入了一个看似随机的区域。
这可能是什么原因造成的?
【问题讨论】: