尝试绘制一个中心内有文本的框,但文本不会与主体同时掉落。文本移动比多边形慢一点,有时当身体停止移动时文本甚至不在正确的位置。
我试着在多边形里面放了一个圆,它可以和多边形同时移动
请就此提出一些建议,以及在不使用 BitmapFont 的情况下执行此操作的任何其他想法?谢谢。
fun draw(batch: SpriteBatch, alpha: Float) {
batch.begin()
if (!projectionMatrixSet) {
shapeRenderer.projectionMatrix = batch.projectionMatrix
}
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled)
shapeRenderer.color = dColor
shapeRenderer.rect(boxBody.position.x - dw, boxBody.position.y - dh, dw*2, dh*2)
shapeRenderer.end()
batch.end()
batch.begin()
if (!projectionMatrixSet) {
circleRenderer.projectionMatrix = batch.projectionMatrix
}
circleRenderer.begin(ShapeRenderer.ShapeType.Filled)
circleRenderer.color = Color.WHITE
circleRenderer.circle(boxBody.position.x , boxBody.position.y, 0.4f)
circleRenderer.end()
batch.end()
batch.begin()
font.data.setScale(0.05f,0.05f);
val layout = GlyphLayout(font, "3", Color.BLACK, dw*2 , Align.center, true);
font.draw(batch, layout, boxBody.position.x - dw, boxBody.position.y + dh)
batch.end()
}