【发布时间】:2021-07-29 01:12:32
【问题描述】:
我为我的 libGDX 游戏创建了一个BitmapFont,并希望在玩家面前渲染它(在空间中的恒定位置,即像一个标志而不像一个 HUD)。可悲的是,渲染在小范围内表现得很奇怪,以至于文本变得不可读。这是怎么回事,有什么办法可以防止这种情况发生?
完整的minimal reproducible example(减去构建/项目文件):
- 使用鼠标光标移动
- 按 ESC 退出应用程序
- 我在屏幕截图之间更改的行是
font.data.setScale(-0.5F, 0.5F)
package xjcl.extracredits2020
import com.badlogic.gdx.*
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.*
import com.badlogic.gdx.math.Vector3
class RangeAnxietyGame : ApplicationAdapter() {
lateinit var cam: PerspectiveCamera
lateinit var spriteBatch: SpriteBatch
lateinit var font: BitmapFont
override fun create() {
Gdx.input.apply { isCursorCatched = true }
spriteBatch = SpriteBatch()
font = BitmapFont()
cam = PerspectiveCamera(67F, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat()).apply {
position.set(Vector3(0f, 1.8f, 0f))
lookAt(0f, 1.8f, 1f)
update()
}
}
override fun render() {
Gdx.gl.glViewport(0, 0, Gdx.graphics.width, Gdx.graphics.height)
Gdx.gl.glClearColor(0f, 0f, 0f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT)
if (Gdx.input.isKeyPressed(Input.Keys.F))
Gdx.graphics.setFullscreenMode(Gdx.graphics.displayMode)
if (Gdx.input.isKeyPressed(Input.Keys.G))
Gdx.graphics.setWindowedMode(1280, 720)
if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE))
Gdx.app.exit()
val dt = Gdx.graphics.deltaTime // seconds
cam.apply {
rotate(Gdx.input.deltaX * -20*dt, 0F, 1F, 0F)
rotate(up.cpy().crs(direction), Gdx.input.deltaY * 10*dt)
Gdx.input.setCursorPosition(Gdx.graphics.width/2, Gdx.graphics.height/2)
update()
}
spriteBatch.apply { // goal text -- bad and hacky
begin()
projectionMatrix = cam.combined.cpy().translate(0F, 0F, 50F)
font.data.setScale(-0.5F, 0.5F)
font.draw(this, "${cam.position.z.toInt()}m/50m\n${Gdx.graphics.width}x${Gdx.graphics.height} " +
"${(1 / dt).toInt()}fps\nat scale (-0.5F, 0.5F)", 0F, 0F)
end()
}
}
}
此外,捕获光标首先工作但随后中断(如果我使用F 进入全屏,然后使用G 退出,则光标可以从各个方向逃逸。我也可以全屏逃逸到我的第二台显示器。 setCursorPosition 没有区别。)我应该为此发布一个单独的问题吗?
【问题讨论】: