For my 2 dimensional Tower Defense game I decided to try it out on a different computer. This turned out to be a disaster… The game runs completely different. randomely lags and everything goes much faster. I am guessing it is the way I do my animations and game loop. Here is the code for the loop:
public void run() {
while (inRealGame) {
if (inGame) {
if (!isFirst) {
room.physic();
mobSpawner();
for (int i = 0; i < currLevel.mobs.length; i++) {
if (currLevel.mobs[i].inGame) {
currLevel.mobs[i].physic();
}
}
if (currLevel.levelOver) {
getNextLevel(currLevel);
}
}
}
try {
Thread.sleep(gameSpeed);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
}
}
And the way I do my animations is I have two variables and an if loop seeing if the first lvariables has become larger than the other and if it has than set that to zero, switch the image. If not increment the variable by one. Any ideas??