What isn't working exactly?
Take a look at this piece of code:
Code:
if (destination.x < position.x) {
position.x -= Math.ceil(speed * d);
}
The problem here is that you're using Math.ceil. Lets say your frame rate is 60 which means the delta will be 1000/60 ≈ 16.
You want your player to move exactly one grid cell (which is lets say 32 pixels). That means he have to move 32 pixels in one second = 32/1000 = 0.032 pixels per millisecond. Since your delta value is 16, the speed increase each frame will be 0.032 * 16 = 0.512.
Here lies the problem with Math.ceil. the 0.512 is getting rounded up to 1. So instead of moving 32 pixels per second, the player instead moves 60. And you can't just decrease the speed, since it will always round up to 1.
Math.ceil is bad in this case. Remove it. Instead, make your player position variables floats/doubles (preferably floats) instead of ints if you haven't already. Since you cant render something using floats, you'll have to convert them into ints before you do that. player.render((int)player.x, (int)player.y);.
Try changing the movement code to this instead:
Code:
// speed = tiles per seconds.
// gridSize = the size of each cell in the grid measured in pixels.
if (destination.x > player.x) {
player.x += speed*gridSize*delta/1000f;
}
Using that, it's really easy to set the correct speed. Please note the 'f' in delta/1000f. It must be there to specify that the 1000 is a float and not an integer. If it was an integer, then delta would be divided using integer division and it would always be 0.
Try doing this and then report back if it still doesn't work. Good luck!