From 90507ffd0b00f823f990a3e1eec84e623dde04c4 Mon Sep 17 00:00:00 2001 From: fredboy Date: Tue, 23 Apr 2024 09:10:52 +0700 Subject: [PATCH] Refactor input handrling --- .../ru/deadsoftware/cavedroid/game/GameRenderer.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java index b54bead..6295011 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java @@ -62,6 +62,8 @@ public class GameRenderer extends Renderer { Gdx.gl.glClearColor(0f, .6f, .6f, 1f); } + private float mTouchDownX, mTouchDownY; + private void updateCameraPosition() { Player player = mMobsController.getPlayer(); setCamPos(player.getX() + player.getWidth() / 2 - getWidth() / 2, @@ -145,6 +147,9 @@ public class GameRenderer extends Renderer { float touchX = transformScreenX(screenX); float touchY = transformScreenY(screenY); + mTouchDownX = touchX; + mTouchDownY = touchY; + if (mMainConfig.isTouch()) { @CheckForNull TouchButton touchedKey = getTouchedKey(touchX, touchY); if (touchedKey != null && touchedKey.isMouse()) { @@ -159,6 +164,13 @@ public class GameRenderer extends Renderer { @Override public boolean touchDragged(int screenX, int screenY, int pointer) { + float touchX = transformScreenX(screenX); + float touchY = transformScreenY(screenY); + + if (Math.abs(touchX - mTouchDownX) < 16 && Math.abs(touchY - mTouchDownY) < 16) { + return false; + } + @CheckForNull MouseInputAction action = mMouseInputActionMapper.mapDragged(screenX, screenY, getCameraViewport()); return handleMouseAction(action); -- 2.29.2