-1
I have this code in my game and I check if it’s past 400 milliseconds, and then update.
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 you end up crashing my game, like I fix?
Are you doing everything in a single thread? You could spare the processor using
Sleep
of Java, not to mention that it would allow another thread to do its work without resource competition– Jefferson Quesado
Are you using Swing? If you are, please, read this answer.
– Victor Stafusa