I added some code using java.util.Timer to execute my spawnMonster function every 100ms. It worked, until I tried instantiating images in it -- since it doesn't run on the libGDX core thread, there's no OpenGL context, so it can't do stuff with images.
I figured using the libGDX Timer class, which the javadocs say runs on the core thread, would solve this problem; but unfortunately, the timer code just doesn't execute.
I tried:
- new Timer().scheduleTask(task, 0, 100) - new Timer().scheduleTask(task, 0, 100, 99999) - Timer.schedule(task, 0, 100) - Timer.schedule(task, 0, 999999) - Timer.start() - t = new Timer(); t.scheduleTask(...); t.start();
task appears to execute once, and only once; it never executes again. (It prints a date-time diff from a target time, so I can tell it's not running.)
new Timer(task, 1, 1)seems to work, but I wonder about the performance of this. \$\endgroup\$new Timer(task, 0, 1)also works, with the same caveats. \$\endgroup\$