[Solved] drawString in loop writes only once instead of multiple times [closed]


A simple test proves the loop indeed works as intended:

 public static void main(String[] args)
    {
        int enemysno = 5;
        for (int i = 0; i < enemysno; i++)
        {
            System.out.println("lalala " + i);
        }
    }

this works fine producing

lalala 0
lalala 1
lalala 2
lalala 3
lalala 4

It was kind of obvious, but via debugging or such a test you could determine that the loop itself is entered the desired numer of times. The problem must be in your string display: most probably your drawString method overwrites the printed string each time.

It should be obvious if you checked the numbers on your output.

The solution?

use a string builder to concatenate the partial strings and then draw the final string using your drawString method

1

solved drawString in loop writes only once instead of multiple times [closed]