From e8b2b04c62058b4f809ef1cd4ffc1c68e67f5255 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 12 Aug 2019 03:04:16 +0900 Subject: [PATCH] no stuttering zoom (inefficient) --- .../terrarum/modulebasegame/IngameRenderer.kt | 24 +++++++++++++++---- .../modulebasegame/ui/UIScreenZoom.kt | 2 +- .../terrarum/worlddrawer/WorldCamera.kt | 13 +++++----- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 95b05cf3f..20d3ee102 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -250,11 +250,17 @@ object IngameRenderer : Disposable { aTex.bind(1) Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it + batch.inUse { blendNormal(batch) batch.shader = shaderBlendGlow shaderBlendGlow.setUniformi("tex1", 1) - batch.draw(rgbTex, 0f, 0f, rgbTex.width * zoom, rgbTex.height * zoom) + batch.draw(rgbTex, + -0.5f * rgbTex.width * zoom + 0.5f * rgbTex.width, + -0.5f * rgbTex.height * zoom + 0.5f * rgbTex.height, + rgbTex.width * zoom, + rgbTex.height * zoom + ) } @@ -268,8 +274,12 @@ object IngameRenderer : Disposable { batch.inUse { blendNormal(batch) batch.shader = null - batch.draw(rgbTex, 0f, 0f, rgbTex.width * zoom, rgbTex.height * zoom) - + batch.draw(rgbTex, + -0.5f * rgbTex.width * zoom + 0.5f * rgbTex.width, + -0.5f * rgbTex.height * zoom + 0.5f * rgbTex.height, + rgbTex.width * zoom, + rgbTex.height * zoom + ) // indicator batch.color = Color.RED @@ -291,8 +301,12 @@ object IngameRenderer : Disposable { batch.inUse { blendNormal(batch) batch.shader = null - batch.draw(aTex, 0f, 0f, aTex.width * zoom, aTex.height * zoom) - + batch.draw(aTex, + -0.5f * aTex.width * zoom + 0.5f * aTex.width, + -0.5f * aTex.height * zoom + 0.5f * aTex.height, + aTex.width * zoom, + aTex.height * zoom + ) // indicator batch.color = Color.WHITE diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt index 328d0e7c6..ac04e9a77 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt @@ -21,7 +21,7 @@ class UIScreenZoom : UICanvas( override var width = AppLoader.fontGame.getWidth(zoomText) override var height = AppLoader.fontGame.lineHeight.toInt() - override var openCloseTime = 0.3f + override var openCloseTime = 0.2f override val mouseUp = false diff --git a/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt b/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt index cb182757b..c299b9c6e 100644 --- a/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt +++ b/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt @@ -2,7 +2,6 @@ package net.torvald.terrarum.worlddrawer import com.jme3.math.FastMath import net.torvald.terrarum.AppLoader -import net.torvald.terrarum.Terrarum import net.torvald.terrarum.floorInt import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameactors.ActorWithBody @@ -15,8 +14,8 @@ import org.dyn4j.geometry.Vector2 object WorldCamera { private val TILE_SIZE = CreateTileAtlas.TILE_SIZE - val zoom: Float - get() = Terrarum.ingame?.screenZoom ?: 1f + //val zoom: Float + // get() = Terrarum.ingame?.screenZoom ?: 1f var x: Int = 0 // left position private set @@ -27,9 +26,9 @@ object WorldCamera { var yEnd: Int = 0 // bottom position private set inline val gdxCamX: Float // centre position - get() = (x + width / 2f * zoom).toInt().toFloat() + get() = xCentre.toFloat() inline val gdxCamY: Float// centre position - get() = (y + height / 2f * zoom).toInt().toFloat() + get() = yCentre.toFloat() var width: Int = 0 private set var height: Int = 0 @@ -44,8 +43,8 @@ object WorldCamera { fun update(world: GameWorld, player: ActorWithBody?) { if (player == null) return - width = FastMath.ceil(AppLoader.screenW / zoom) // div, not mul - height = FastMath.ceil(AppLoader.screenH / zoom) + width = AppLoader.screenW//FastMath.ceil(AppLoader.screenW / zoom) // div, not mul + height = AppLoader.screenH//FastMath.ceil(AppLoader.screenH / zoom) // TOP-LEFT position of camera border