I have a little code for testing a sprite, that I want to move with the mouse. When I click the screen, the sprite has to move to the clicked point. But something weird is going on.
I'm running it in a thread, called Controls, that extends to Thread and implements MouseListener, and using the following code, the sprite moves.
public void run() {
while(true){
if((int)point.getX() > player.getX()){
while((int)point.getX() > player.getX()){
player.moveX(1);
}
}
else{
System.out.println("Nah!");
}
}
}
Everything works as expected, but if i do this:
public void run() {
while(true){
if((int)point.getX() > player.getX()){
while((int)point.getX() > player.getX()){
player.moveX(1);
}
}
}
}
It doesn't work. If i do this:
public void run() {
while(true){
if((int)point.getX() > player.getX()){
while((int)point.getX() > player.getX()){
player.moveX(1);
}
}
else{
}
}
}
It doesn't work either. I have no idea of what is going on, any ideas?
Aucun commentaire:
Enregistrer un commentaire