mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
drawing droppeditem using common draw positioning function just like others
This commit is contained in:
@@ -1651,35 +1651,12 @@ open class ActorWithBody : Actor {
|
|||||||
protected fun drawSpriteInGoodPosition(sprite: SpriteAnimation, batch: SpriteBatch) {
|
protected fun drawSpriteInGoodPosition(sprite: SpriteAnimation, batch: SpriteBatch) {
|
||||||
if (world == null) return
|
if (world == null) return
|
||||||
|
|
||||||
//val offendingPad = world!!.width.times(TILE_SIZE) - WorldCamera.width - 1
|
|
||||||
|
|
||||||
val offsetX = (hitboxTranslateX * scale).toFloat()
|
val offsetX = (hitboxTranslateX * scale).toFloat()
|
||||||
val offsetY = (sprite.cellHeight * scale - hitbox.height - hitboxTranslateY * scale - 1).toFloat()
|
val offsetY = (sprite.cellHeight * scale - hitbox.height - hitboxTranslateY * scale - 1).toFloat()
|
||||||
|
|
||||||
drawBodyInGoodPosition(hitbox.startX.toFloat(), hitbox.startY.toFloat()) { x, y ->
|
drawBodyInGoodPosition(hitbox.startX.toFloat(), hitbox.startY.toFloat()) { x, y ->
|
||||||
sprite.render(batch, x - offsetX, y - offsetY, scale.toFloat())
|
sprite.render(batch, x - offsetX, y - offsetY, scale.toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
sprite.render(batch,
|
|
||||||
(hitbox.startX - offsetX).toFloat(),
|
|
||||||
(hitbox.startY - offsetY).toFloat(),
|
|
||||||
(scale).toFloat()
|
|
||||||
)
|
|
||||||
|
|
||||||
batch.color = Color.BLUE
|
|
||||||
sprite.render(batch,
|
|
||||||
(hitbox.startX - offsetX).toFloat() - world!!.width * TILE_SIZEF,
|
|
||||||
(hitbox.startY - offsetY).toFloat(),
|
|
||||||
(scale).toFloat()
|
|
||||||
)
|
|
||||||
|
|
||||||
batch.color = Color.GREEN
|
|
||||||
sprite.render(batch,
|
|
||||||
(hitbox.startX - offsetX).toFloat() + world!!.width * TILE_SIZEF,
|
|
||||||
(hitbox.startY - offsetY).toFloat(),
|
|
||||||
(scale).toFloat()
|
|
||||||
)*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActorValueChange(key: String, value: Any?) {
|
override fun onActorValueChange(key: String, value: Any?) {
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.BlockCodex
|
import net.torvald.terrarum.BlockCodex
|
||||||
import net.torvald.terrarum.ItemCodex
|
import net.torvald.terrarum.ItemCodex
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZEF
|
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
import net.torvald.terrarum.gameactors.PhysProperties
|
import net.torvald.terrarum.gameactors.PhysProperties
|
||||||
|
import net.torvald.terrarum.gameactors.drawBodyInGoodPosition
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-03-15.
|
* Created by minjaesong on 2016-03-15.
|
||||||
@@ -66,37 +66,16 @@ open class DroppedItem : ActorWithBody {
|
|||||||
// copy-pasted from ActorWithBody.drawSpriteInGoodPosition()
|
// copy-pasted from ActorWithBody.drawSpriteInGoodPosition()
|
||||||
if (world == null) return
|
if (world == null) return
|
||||||
|
|
||||||
|
|
||||||
val leftsidePadding = world!!.width.times(TILE_SIZE) - WorldCamera.width.ushr(1)
|
|
||||||
val rightsidePadding = WorldCamera.width.ushr(1)
|
|
||||||
|
|
||||||
val offsetX = hitboxTranslateX * scale
|
|
||||||
val offsetY = (textureRegion?.regionHeight ?: TILE_SIZE) * scale - hitbox.height - hitboxTranslateY * scale - 1
|
|
||||||
|
|
||||||
textureRegion?.let {
|
textureRegion?.let {
|
||||||
// FIXME test me: this extra IF statement is supposed to not draw actors that's outside of the camera.
|
val offsetX = (hitboxTranslateX * scale).toFloat()
|
||||||
// basic code without offsetX/Y DOES work, but obviously offsets are not tested.
|
val offsetY = (it.regionHeight * scale - hitbox.height - hitboxTranslateY * scale - 1).toFloat()
|
||||||
if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) {
|
|
||||||
// camera center neg, actor center pos
|
drawBodyInGoodPosition(hitbox.startX.toFloat(), hitbox.startY.toFloat()) { x, y ->
|
||||||
batch.draw(it,
|
batch.draw(it,
|
||||||
(hitbox.startX - offsetX).toFloat() + world!!.width * TILE_SIZE,
|
FastMath.floor(x - offsetX).toFloat(),
|
||||||
(hitbox.startY - offsetY).toFloat(),
|
FastMath.floor(y - offsetY).toFloat(),
|
||||||
TILE_SIZEF * scale.toFloat(), TILE_SIZEF * scale.toFloat()
|
Math.floor(it.regionWidth * scale).toFloat(),
|
||||||
)
|
Math.floor(it.regionHeight * scale).toFloat()
|
||||||
}
|
|
||||||
else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) {
|
|
||||||
// camera center pos, actor center neg
|
|
||||||
batch.draw(it,
|
|
||||||
(hitbox.startX - offsetX).toFloat() - world!!.width * TILE_SIZE,
|
|
||||||
(hitbox.startY - offsetY).toFloat(),
|
|
||||||
TILE_SIZEF * scale.toFloat(), TILE_SIZEF * scale.toFloat()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
batch.draw(it,
|
|
||||||
(hitbox.startX - offsetX).toFloat(),
|
|
||||||
(hitbox.startY - offsetY).toFloat(),
|
|
||||||
TILE_SIZEF * scale.toFloat(), TILE_SIZEF * scale.toFloat()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user