I have this method and it have some bug which makes the character to slide over the wall until I move it.The bug starts when I'm touching the wall and pressing 2 buttons at a time.
void collision()
{
if(this.isTouching(Wall.class))
{
if(direction == 1) //up
{
setLocation(getX(), getY() + speed);
}
else if(direction == 2)//down
{
setLocation(getX(), getY() - speed);
}
else if(direction == 3)//right
{
setLocation(getX() - speed, getY());
}
else if(direction == 4)//left
{
setLocation(getX() + speed, getY());
}
}
}

