So I need help to make my character move more smoothly. The problem is that the character moves one pixel when I press a key and after like one second he runs "smoothly" after that. How can I fix it so that I don't need to wait that one second and he just runs smoothly from the beginning? I appreciate any help and thanks before hand!
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.GREEN);
g.fillRect(x, y, 30, 30);
update();
}
private boolean[] KB = new boolean[4];
public void update(){
if(KB[0] = true)
{
y -= 10;
}
if(KB[1] = true)
{
x -= 10;
}
if(KB[2] = true)
{
y += 10;
}
if(KB[3] = true)
{
x +=10;
}
repaint();
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_W)
{
KB[0] = true;
}
if(e.getKeyCode() == KeyEvent.VK_A)
{
x -= 10;
}
if(e.getKeyCode() == KeyEvent.VK_S)
{
y += 10;
}
if(e.getKeyCode() == KeyEvent.VK_D)
{
x += 10;
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {