Thank you for replies, trollwarrior1 and rwatson462!
I figured out there is something else wrong with the movement of entity. So, here’s how the movement works. Once entity’s destination (variables newX and newY) are set, entity moves towards those coordinates first on x-axis, then on y-axis. But, there is a problem. This only works if speed is set to 16, otherwise either newX or newY will never be equal to entity’s x or y. Here’s the code:
public void update(float delta){
float x = sprite.getX();
float y = sprite.getY();
float speed = (float) Math.floor(950 * delta);
if(speed < 16 || speed > 16)
speed = 16;
if(x != newX){
if(x < newX){
sprite.setX(x + speed);
}else if(x > newX){
sprite.setX(x - speed);
}
moving = true;
}
if(y != newY){
if(y < newY){
sprite.setY(y + speed);
}else if(y > newY){
sprite.setY(y - speed);
}
moving = true;
}
if(x == newX && y == newY){
moving = false;
}
}
I tried working around this problem, but then the movement turned to tile-based on x-axis, and never finished on y-axis. Here’s the code:
public void update(float delta){
float x = sprite.getX();
float y = sprite.getY();
float speed = 64;
if(x != newX){
if(x > newX - 1){
sprite.setX(newX);
return;
}else if(x < newX + 1){
sprite.setX(newX);
return;
}else{
if(x < newX){
sprite.setX(x + speed * delta);
}else if(x > newX){
sprite.setX(x - speed * delta);
}
moving = true;
}
}
if(y != newY){
if(y - 1 > newY && y + 1 < newY){
sprite.setY(newY);
}else{
if(y < newY){
sprite.setY(y + speed * delta);
}else if(y > newY){
sprite.setY(y - speed * delta);
}
moving = true;
}
}
if(x == newX && y == newY){
moving = false;
}
}
I’m not sure if I’m becoming dumber because it seems like this problem has a very simple solution. Someone help me, please? 