Game Development Reference
In-Depth Information
Figure 6-5 . Organize the .start() method with the createSplashScreenNodes() and addNodesToStackPane() methods
As you can see, after you duplicate the .setOnAction() constructs for each Button
object, when you collapse the EventHandler routines, you have nine lines of code: one
for creating nodes, one for adding nodes to root, three for Stage object setup, and four
for UI Button event-handling. This is pretty compact, if you consider the amount of
functionality you are adding to the top level of your game structure (game play, instruc-
tions, legal, credits, scoreboard).
It is important that you do things in the correct order, as some Java code is predic-
ated on other Java code. For this reason, the object declarations come first; then, inside
the .start() method, you create (instantiate) the nodes. Once these are declared, named,
and instantiated (created), you add them to the StackPane root node and then configure
(using the .setTitle() method) and add the scene Scene object to the primaryStage Stage
object, using the .setScene() method. After your objects are in system memory, only
then will you be able to process ActionEvent handling routines, which are attached to
your four Button UI controls. Next, let's make sure that your digital image assets,
which will be referenced in the createSplashScreenNodes() method, are in the proper
NetBeans folder.
 
Search WWH ::




Custom Search