I've made simple custom actor in 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();
}
}
I'am rendering around 30 of this on stage 2d in group.
Problem is that rendering this costs me around 20 frames per second. Rendering same number of simple Label has no visible performance impact. I am missing something in this code? Those Actors are added to group which is rendered using Stage.