I recently got into learning Java. I'm trying to get the code to change the picture representing the player at set intervals when a movement key is pressed.
Below is my code. I'm trying to create the image loop within the if statement so that 'currentSprite' will equal 'CharacterRight' 'CharacterRight1' 'CharacterRight2' respectively, then restart from 'CharacterRight' until (player.isMovingRight()) is no longer true.
public void run() {
while (true) {
player.update();
if (player.isMovingRight()) {
currentSprite = characterRight;
}
bg1.update();
bg2.update();
repaint();
try {
Thread.sleep(17);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
It seems like there should be a relatively easy way to accomplish this. I'm sorry if it is a nooby question.
If anyone can help me, I would be eternally grateful.