Im making a game over the summer break and im having trouble with dealing with the walking animation. Im trying to put a stepping animation in between moving to the left or right trying to invoke repaint() for the first animation with a thread.sleep() inbetween followed by another repaint().
case 65 :
paintNum = 4;
x = x-10;
panel.changeNum(4);
panel.setX(x);
panel.repaint(200);
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
panel.changeNum(3);
panel.repaint();
//a
break;
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
super.paintComponent(g);
g2.drawImage(list.get(paintNum),x,y,50,50,null);
}
public void changeNum(int num) {
paintNum =num;
}
public void setX(int num) {
x = x +num;
}
public void setY(int num) {
y = y+ num;
}
My code takes the break but skips the first repaint and goes straight to the second one. For context I have the movement in a switch case in another class that calls on the paint() method in my panel class. The paintNum is just the number for an array of the walking images.