Game Development Reference
In-Depth Information
I think that is enough class background information for now, so let's get into writ-
ing the code for your first .createSplashScreenNodes() method, which will instantiate
and set up all the Node objects for your Scene Graph!
Scene
Graph
Nodes:
.createS-
plashScreenNodes()
The first thing you will want to do with your createSplashScreenNodes() method is
code the empty method structure and add the Node object creation code that already
exists in the bootstrap code that was generated for you by NetBeans in Chapter 2 . This
includes the Node objects for the Button node, the StackPane root node, and the Scene
object named scene. You will keep the primaryStage code in the .start() method be-
cause that object is created using the .start(Stage primaryStage) constructor method
call. The Button object has already been renamed gameButton (it was btn), so you have
three lines of object instantiation code and a line of configuration code, as follows:
root = new StackPane();
scene = new Scene( root , 640, 400);
gameButton = new Button();
gameButton.setText("PLAY GAME");
It is important to note that because the root StackPane object is used in the con-
structor method call for the scene Scene object, this line of code needs to come first
(your root object has to be created before it is used!). The next thing you need to create
is the HBox layout container object that will hold your four Button UI controls. You
will also set the alignment attribute for the HBox; add an Insets object to contain the
padding values; and then add this padding to the4 HBox object, using these four lines
of Java code:
buttonContainer = new HBox( 12 );
buttonContainer.setAlignment(Pos. BOTTOM_LEFT );
buttonContainerPadding = new Insets(0, 0, 10, 16);
buttonContainer.setpadding( buttonContainerPadding );
Next, let's take a handy programmers' shortcut and copy and paste the two
gameButton (instantiation and configuration) lines of code below the HBox code (be-
Search WWH ::




Custom Search