0
我試圖讓鼠標點擊+拖動結果移動正交相機相對於初始點擊。用鼠標拖動移動正射相機
我下面的內容幾乎是我想要的。
但是,您可以看到,當我單擊藍色聖馬刁橋南部的區域時,相機會跳到一個奇怪的位置,然後允許相機在整個拖曳中平穩移動。
相機的所有當前操作是通過一類的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;
}
縮放看起來不會影響拖動動作的正確性,因爲它被考慮在內。然而,似乎最初的點擊並沒有像預期的那樣起作用,而是因爲它最初的跳躍並跳入一個看似隨機的區域。
這可能是什麼原因造成的?