I want to display a shot for a game I'm working on. But the canvas just invalidate at the end of my for-loop. It's the same problem like here Canvas do not update (invalidate) until whole while loop ends But the answer doesn't work for me. How can I invalidate my canvas in this case?:
else if (event.getX() > 1150 && event.getX() < 1300
&& event.getY() > 550 && event.getY() < 700)
{
System.out.println("Schuss");
final ArrayList<Shot> positions = game.shot(100, 45, canvas);
new Thread(new Runnable()
{
public void run()
{
for (int i = 0; i < positions.size(); i++)
{
game.setCurrentShot(positions.get(i));
System.out.println(i);
canvas.postInvalidate();
}
}
}).start();
}
In the shot-function I calculate all positions. The shot will pass and then I want to display thoos positions on my canvas, but that dosen't work.