Probably missing something basic, but I have a for-loop in my program that's supposed to iterate over an array (lines[]
) and draw them onscreen (using LWJGL/Slick).
Instead of the lines being shown on separate lines (at (i*16 + 7, 5)
), they all appear at (7, 5)
.
for(int i = 0; i < lines.length; i++) {
if(lines[i] != null) {
f.drawString((i * 16) + 7, 5, lines[i]);
}
}
I have seen answers on other questions suggesting to define a final variable in the loop to avoid the value being changed before the called function uses it. So I have changed the code to:
for(int i = 0; i < lines.length; i++) {
if(lines[i] != null) {
final int i2 = i;
f.drawString((i2 * 16) + 7, 5, lines[i]);
}
}
But it doesn't fix it (didn't really expect it to, as I'm not getting stuck on the last value of i and Slick shouldn't be storing the value of i, but tried it to make sure).
The header of drawString is as follows:
public void drawString(float x, float y, String whatchars)