* method.
*/
public final void start() {
// grabbing engines from master engine
this.grabEngines();
GameFont fpsFont = this.parent.fpsFont;
if (!this.initialized) {
this.initResources();
this.initialized = true;
}
this.finish = false;
// start game loop!
// before play, clear memory (runs garbage collector)
System.gc();
System.runFinalization();
this.bsInput.refresh();
this.bsTimer.refresh();
long elapsedTime = 0;
out: while (true) {
if (this.parent.inFocus) {
// update game
this.update(elapsedTime);
this.parent.update(elapsedTime); // update common variables
this.bsInput.update(elapsedTime);
}
else {
// the game is not in focus!
try {
Thread.sleep(300);
}
catch (InterruptedException e) {
}
}
do {
if (this.finish || !this.parent.isRunning()) {
// if finish, quit this game
break out;
}
// graphics operation
Graphics2D g = this.bsGraphics.getBackBuffer();
this.render(g); // render game
this.parent.render(g); // render global game
if (!this.parent.isDistribute()) {
// if the game is still under development
// draw game FPS and other stuff
// to make sure the FPS is drawn!
// remove any clipping and alpha composite
if (g.getClip() != null) {
g.setClip(null);
}
if (g.getComposite() != null) {
if (g.getComposite() != AlphaComposite.SrcOver) {
g.setComposite(AlphaComposite.SrcOver);
}
}
fpsFont.drawString(g, "FPS = " + this.getCurrentFPS() + "/"
+ this.getFPS(), 9, this.getHeight() - 21);
fpsFont.drawString(g, "GTGE", this.getWidth() - 65, 9);
}
if (!this.parent.inFocus) {
this.parent.renderLostFocus(g);
}