0
我正在使用libGDX實現一個關卡選擇頁面(如憤怒的小鳥)。我有這樣的輔助函數來繪製頁面指示符(點表示當前頁):libGDX形狀渲染器未按下後退按鈕
val shapeRenderer = ShapeRenderer()
fun drawPageIndicator(batch: Batch?, page: Int, pageCount: Int, y: Float, centerX: Float, gap: Float, radius: Float) {
batch?.end();
var fromX = centerX - pageCount/2 * gap;
if (pageCount % 2 == 0) {
fromX += gap/2;
}
shapeRenderer.projectionMatrix = batch?.projectionMatrix
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled)
for (i in 0..pageCount-1) {
if (i == page) {
shapeRenderer.color = Color.WHITE
} else {
shapeRenderer.color = Color.GRAY
}
shapeRenderer.circle(fromX, y, radius)
fromX += gap;
}
shapeRenderer.end()
batch?.begin();
}
然後在繪製函數,我有:
override fun draw(batch: Batch?, parentAlpha: Float) {
super.draw(batch, parentAlpha)
H.drawPageIndicator(batch, scroller.currentPage, scroller.pageCount, indicatorY, scroller.x + scroller.width/2, 16f, 4f)
}
它按預期工作。但每次我點擊後退按鈕(主頁的哪個出口),然後回到級別選擇屏幕,點就消失了。
用'Texture'和'SpriteBatch'代替'shapeRenderer'工作更好# – Aryan