I am trying to make a method that updates every Frame. I am using a thread with an invokeandwait method. My goal is to execute the CashCount method every frame forever. Even though I'm not getting any errors the whole thing just won't work. Please look at the code and help me make this work.
static void UpdateEveryFrame()
{
CashCount();
}
void Update()
{
final Runnable runnable = new Runnable()
{
public void run()
{
UpdateEveryFrame();
}
};
Thread UpdaterThread = new Thread()
{
public void run()
{
long period = 1000 / FPS;
long t0 = System.currentTimeMillis();
while(true)
{
long t1 = System.currentTimeMillis();
if (t1 - t0 == period)
{
do{
try {
SwingUtilities.invokeAndWait(runnable);
}
catch (InvocationTargetException | InterruptedException e) {
e.printStackTrace();
System.exit(1);
}
t0 += period;
} while (t1 - t0 == period);
t0 = t1;
}
}
}
};
UpdaterThread.start();
}