not related to JOGL too but usually I use something similar to the following :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| private long gameLogicLastTime=-1; private long gameLogicRate=10;
public void run() { while(this.mustRun) { this.doLogic(); this.diplay(); Thread.yield(); } }
public void doLogic() { long time=System.currentTimeMillis() if(this.gameLogicLastTime==-1) { this.gameLogicLastTime=time; return; } long elapsedTime=time-this.gameLogicLastTime; if(elapsedTime<this.gameLogicRate) return; int nbGameLogic=(int)(elapsedTime/this.gameLogicRate);
for(int gameLogicCount=0;gameLogicCount<nbGameLogic;gameLogicCount++) this.doLogicOnce(); this.gameLogicLastTime+=nbGameLogic*this.gameLogicRate; }
public void doLogicOnce() {
}
public void display() {
} |