I've been working on a top-down, and the player already has animations for moving left and right. However, if I move a certain distance and stop, it will stop on the walking animation, which isn't logical as opposed to a standing animation while the player is idle.
I've been using this input handler class:
public class InputHandler implements KeyListener
{
public boolean up = false;
public boolean down = false;
public boolean left = false;
public boolean right = false;
public InputHandler(Game game)
{
game.addKeyListener(this);
}
public void toggle(KeyEvent ke, boolean Pressed)
{
int KeyCode = ke.getKeyCode();
if(KeyCode == ke.VK_UP) up = Pressed;
if(KeyCode == ke.VK_DOWN) down = Pressed;
if(KeyCode == ke.VK_LEFT) left = Pressed;
if(KeyCode == ke.VK_RIGHT) right = Pressed;
}
public void keyPressed(KeyEvent e)
{
toggle(e, true);
}
public void keyReleased(KeyEvent e)
{
toggle(e, false);
}
public void keyTyped(KeyEvent e)
{
}
}
and it is coupled with the tick() method from my main class:
private void tick()
{
if(input.right)
{
xScroll++;
if(xScroll / 16 % 2 == 0)
{
dirFacing = 2;
}
if(xScroll / 16 % 2 != 0)
{
dirFacing = 4;
}
}
if(input.left)
{
xScroll--;
if(xScroll / 16 % 2 == 0)
{
dirFacing = 1;
}
if(xScroll / 16 % 2 != 0)
{
dirFacing = 3;
}
}
if(input.down)
{
yScroll++;
}
if(input.up)
{
yScroll--;
}
}
Again, the above yScroll will be added later, I really just need to solve the standing animation first.