Game Development Reference
In-Depth Information
}
} .start();
}
The above programming logic shows how an AnimationTimer inner class would be
constructed as well as how Java dot chaining works. The .start() method call to the
AnimationTimer superclass is appended to the end of the new AnimationTimer(){. . .}
code construct so that the entire AnimationTimer creation ( using new ), declaration (us-
ing the curly braces), and execution (using a .start () method call) are chained to the An-
imationTimer object construct.
If you want to create a more complex AnimationTimer subclass for something cent-
ral to your game logic, such as Collision Detection , it would be a better idea (Java
code design approach) to make this game logic its very own custom AnimationTimer
subclass.
This is especially true if you are going to be creating more than one Anima-
tionTimer subclass to do pulse event-controlled high-speed processing. That's right,
you can have more than one AnimationTimer subclass running at the same time (just
do not get carried away and use too many AnimationTimers). You can accomplish this
with the extends keyword, creating your own AnimationTimer class, called
GamePlayLoop , using the following class definition:
public class GamePlayLoop extends AnimationTimer {
@Override
public void handle(long now) {
// Program logic that gets processed on every
pulse that JavaFX processes
}
@Override
public void start() {
super.start();
}
@Override
public void stop() {
super.stop();
}
}
Next, let's investigate the JavaFX Stage class (object),which is passed into your In-
vinciBagel .start() method!
Search WWH ::




Custom Search