我已經在libGdx中做了一個簡單的自定義actor。LibGdx渲染多個自定義演員的性能
public class HealthBar extends Actor {
private Texture background;
private Texture bar;
private float max;
private float current;
public HealthBar(Color bgColor, Color barColor) {
Pixmap bgPixmap = new Pixmap(1, 1, Pixmap.Format.RGB565);
bgPixmap.setColor(bgColor);
bgPixmap.drawPixel(0, 0);
background = new Texture(bgPixmap);
bgPixmap.dispose();
Pixmap barPixmap = new Pixmap(1, 1, Pixmap.Format.RGB565);
barPixmap.setColor(barColor);
barPixmap.drawPixel(0, 0);
bar = new Texture(barPixmap);
barPixmap.dispose();
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(background, getX(), getY(), getWidth(), getHeight());
batch.draw(bar, getX(), getY(), getBarEnd(), getHeight());
}
private float getBarEnd() {
return current/max * getWidth();
}
public void setHealth(float current, float max) {
this.current = current;
this.max = max;
}
public void dispose(){
background.dispose();
bar.dispose();
}
}
我'在組渲染此大約30上階段2d上。
問題是渲染會導致我花費20幀/秒左右。呈現相同數量的簡單標籤沒有明顯的性能影響。我在這段代碼中缺少一些東西?這些Actor被添加到使用Stage呈現的組中。
performance with draw() content commented
謝謝你的好評!我認爲只有當我調用flush()方法時纔會刷新批處理。它在低端Android設備上進行了測試。在Nvidia Shield平板電腦遊戲中,該手機擁有20-30fps的穩定60fps。 –