Smoother map panning

This commit is contained in:
Yair Morgenstern
2021-01-25 19:23:48 +02:00
parent 93bdb137f9
commit 48f68c6bd0

View File

@ -80,7 +80,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
try { // Most memory errors occur here, so this is a sort of catch-all try { // Most memory errors occur here, so this is a sort of catch-all
mapHolder.addTiles() mapHolder.addTiles()
} catch (outOfMemoryError:OutOfMemoryError){ } catch (outOfMemoryError: OutOfMemoryError) {
mapHolder.clear() // hopefully enough memory will be freed to be able to display the toast popup mapHolder.clear() // hopefully enough memory will be freed to be able to display the toast popup
ToastPopup("Not enough memory on phone to load game!", this) ToastPopup("Not enough memory on phone to load game!", this)
} }
@ -183,7 +183,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
object : InputListener() { object : InputListener() {
private val pressedKeys = mutableSetOf<Int>() private val pressedKeys = mutableSetOf<Int>()
private var infiniteAction: RepeatAction? = null private var infiniteAction: RepeatAction? = null
private val amountToMove = 30 / mapHolder.scaleX private val amountToMove = 6 / mapHolder.scaleX
private val ALLOWED_KEYS = setOf(Input.Keys.W, Input.Keys.S, Input.Keys.A, Input.Keys.D, private val ALLOWED_KEYS = setOf(Input.Keys.W, Input.Keys.S, Input.Keys.A, Input.Keys.D,
Input.Keys.UP, Input.Keys.DOWN, Input.Keys.LEFT, Input.Keys.RIGHT) Input.Keys.UP, Input.Keys.DOWN, Input.Keys.LEFT, Input.Keys.RIGHT)
@ -194,7 +194,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
pressedKeys.add(keycode) pressedKeys.add(keycode)
if (infiniteAction == null) { if (infiniteAction == null) {
// create a copy of the action, because removeAction() will destroy this instance // create a copy of the action, because removeAction() will destroy this instance
infiniteAction = Actions.forever(Actions.delay(0.05f, Actions.run { whileKeyPressedLoop() })) infiniteAction = Actions.forever(Actions.delay(0.01f, Actions.run { whileKeyPressedLoop() }))
mapHolder.addAction(infiniteAction) mapHolder.addAction(infiniteAction)
} }
return true return true