I have this code in my game and check if it has passed 400 milliseconds, and then it updates.
public void setUpdatePosition(int posicao, long tempo, int posX, int posY) {
long previous = System.nanoTime();
Point ponto = new Point(tiles[posicao].x, tiles[posicao].y);
tiles[posicao].setPosition(posX, posY);
while(((System.nanoTime() - previous) / 1000000) < tempo) {
previous = System.nanoTime();
}
tiles[posicao].setPosition(ponto.x, ponto.y);
}
But it ends up locking my game, how do I solve it?