How to make main method (or any user defined method) work like greenfoot act method?
public void act()
{
}public void act()
{
}
public class Simulation {
private boolean active = true;
private long stepDuration = 20;
private World world;
public void run() {
long lastCallTime;
while (active) {
lastCallTime = System.currentTimeMillis();
world.act();
final long timeTillNextStep = lastCallTime + stepDuration - System.currentTimeMillis();
if (timeTillNextStep > 0) {
Thread.sleep(timeTillNextStep);
}
}
}
}