mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
implementing the iconic 'lag behind' camera the right way
This commit is contained in:
@@ -505,8 +505,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
// camera-related updates //
|
// camera-related updates //
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
FeaturesDrawer.update(delta)
|
FeaturesDrawer.update(delta)
|
||||||
WorldCamera.update(gameworld, actorNowPlaying)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
@@ -529,6 +527,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
visibleActorsRenderMidTop = actorsRenderMidTop.filter { it.inScreen() }
|
visibleActorsRenderMidTop = actorsRenderMidTop.filter { it.inScreen() }
|
||||||
visibleActorsRenderFront = actorsRenderFront.filter { it.inScreen() }
|
visibleActorsRenderFront = actorsRenderFront.filter { it.inScreen() }
|
||||||
visibleActorsRenderOverlay=actorsRenderOverlay.filter { it.inScreen() }
|
visibleActorsRenderOverlay=actorsRenderOverlay.filter { it.inScreen() }
|
||||||
|
|
||||||
|
|
||||||
|
WorldCamera.update(gameworld, actorNowPlaying)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package net.torvald.terrarum.worlddrawer
|
|||||||
|
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
|
||||||
import net.torvald.terrarum.floorInt
|
import net.torvald.terrarum.floorInt
|
||||||
|
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||||
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
|
import org.dyn4j.geometry.Vector2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-12-30.
|
* Created by minjaesong on 2016-12-30.
|
||||||
@@ -29,6 +30,8 @@ object WorldCamera {
|
|||||||
inline val yCentre: Int
|
inline val yCentre: Int
|
||||||
get() = y + height.ushr(1)
|
get() = y + height.ushr(1)
|
||||||
|
|
||||||
|
private val nullVec = Vector2(0.0, 0.0)
|
||||||
|
|
||||||
fun update(world: GameWorld, player: ActorWBMovable?) {
|
fun update(world: GameWorld, player: ActorWBMovable?) {
|
||||||
if (player == null) return
|
if (player == null) return
|
||||||
|
|
||||||
@@ -38,12 +41,14 @@ object WorldCamera {
|
|||||||
// TOP-LEFT position of camera border
|
// TOP-LEFT position of camera border
|
||||||
|
|
||||||
// some hacky equation to position player at the dead centre
|
// some hacky equation to position player at the dead centre
|
||||||
// NOT tested for WorldDrawer sampling negative coord for its drawing (which causes some fucking artefacts)
|
// implementing the "lag behind" camera the right way
|
||||||
x = ((player.hitbox.centeredX).toFloat() - (width / 2)).floorInt() // X only: ROUNDWORLD implementation
|
val pVecSum = player.externalV + (player.controllerV ?: nullVec)
|
||||||
|
|
||||||
|
x = ((player.hitbox.centeredX - pVecSum.x).toFloat() - (width / 2)).floorInt() // X only: ROUNDWORLD implementation
|
||||||
|
|
||||||
|
|
||||||
y = (FastMath.clamp(
|
y = (FastMath.clamp(
|
||||||
player.hitbox.centeredY.toFloat() - height / 2,
|
(player.hitbox.centeredY - pVecSum.y).toFloat() - height / 2,
|
||||||
TILE_SIZE.toFloat(),
|
TILE_SIZE.toFloat(),
|
||||||
world.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
world.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||||
)).floorInt().clampCameraY(world)
|
)).floorInt().clampCameraY(world)
|
||||||
|
|||||||
Reference in New Issue
Block a user