My renderBoard is slow and it's because of font.draw function. I read that I should use stringBuilder instead of string, but it didn't help at all. I suppose I'm using it wrong. Could you guide me to the right way?
public void renderBoard(SpriteBatch sb, BitmapFont font) {
int L = 0;
String string;
...
// "size" is a private variable of the class, the same goes for "stringBuilder"
for(int k = - size + 1; k <= size - 1; k++) {
for (int j = 1; j <= size - Math.abs(k); j++) {
string = L + "";
for(int g = 0; g < string.length(); g++) {
stringBuilder.setCharAt(g, string.charAt(g));
}
sb.draw(
this.getTexturesArray().get(L),
x_j_k_position,
y_j_k_position
);
font.setColor(Color.WHITE);
font.draw(
sb,
stringBuilder,
x_j_k_position,
y_j_k_position
);
L++;
}
}
}
If I comment out the font.draw line, the game accelerates, so I guess here lies the problem.