I want to move a game object from its current position to the mouse position, but my current code only ever moves in one of the eight ordinal directions. In other words, I want it to move along the red path, but I only know how to move it along the white path.
Here's my code:
while(cont){
if(x1 > x){
x++;
}else if(x1 < x){
x--;
}
if(y1 > y){
y++;
}else if(y1 < y){
y--;
}
frame.repaint();
sleep(); // Thread.sleep(200)
}
// x1 y1 - mouse position
// x, y - sprite position
What am I missing?